JQuery find () function

I am trying to move lines from name attributes to src of each img. I am using jQuery for this:

$("#one").find("img").attr("src",$(this).attr("name"); 

Now the problem is that $ (this) is not the current managed item. So, how do I get the current element found by find ()?

+4
source share
1 answer

attr method accepts a function, in the context of this function this refers to the current element:

 $("#one").find("img").attr("src", function(){ return this.name }); 
+6
source

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


All Articles