Unidentified jQuery.click () function issue

I am trying to add the onclick function to an image using jQuery and for some reason it does not stick. My code looks like this:

//create arrow icon/button for li
var img = $('<img></ >').attr('id',i+5)
                       .attr("src","images/16-arrow-right.png")
                       .addClass("expImg")
                       .click(function(){expand(this, 'tdb', 'years', 'danwoods')})
                       .appendTo(li);   

and the resulting element is as follows:

<img id="6" src="images/16-arrow-right.png" class="expImg"/>

It completely eliminates the onclick function, but everything else works fine. Does anyone see a problem with my code, or is the error somewhere else? Thanks in advance...

+3
source share
1 answer

, click, , HTML- . " onclick"; DOM, . -, , .

, , :

.attr('onclick', "expand(this, 'tdb', 'years', 'danwoods')")

, .

+4

Source: https://habr.com/ru/post/1720329/


All Articles