Reputation: 57
Today I have a problem. I can't get and change value in array Childnotes. I try find in stackoverflow but not results as expected
var $this = $(this);
When Debug, I receive image follow:
I want to get value and change value in childNotes: NodeList[3] --> 1:img --> change attributes: src in img
Upvotes: 0
Views: 354
Reputation: 15148
Maybe you can try something like:
$(this).children("img").attr("src", "mycool_image.jpg");
This will find the direct children -> if you have them nested deeper, you can use find()
instead.
$(this).find("img").attr("src", "mycool_image.jpg");
EDIT
If you want the n-th child img
element then you can do:
$(this).find("img").eq(2).attr("src", "mycool_image.jpg");
EDIT2
To get the source before changing it simply do (by supplying the correspondent index to eq()
of course):
var source = $(this).find("img").eq(2).attr("src");
Upvotes: 1
Reputation: 1435
I think that you would like to change some attr src from image tag inside your tag
So, you can use your reference $this (tag ) to find your specific image tag and do whatever your want:
...
var $this = $(this);
$this.find("img").attr("src", "some_value");
...
If you have more than one image tags and you want to change just the third tag, you should mark it with some "data-attribute", like this:
$this.find("img[data-changeable]").attr("src", "some_value");
Upvotes: 1