selector - Add class to parent of <img> with certain class name or certain source -


my html looks this, , i'm working yui library:

<div>     <img class="smallimage" src="host/smallimage.jpg"> </div> <div>     <img src="host/bigimage.jpg"> </div> 

i know how
(1) add class container off images class of .smallimage
(2) add class container of images string 'big' in source tag. :)

so output this:

<div class = "small">     <img class="smallimage" src="host/smallimage.jpg"> </div> <div class = "big">     <img src="host/bigimage.jpg"> </div> 

thanks fellas!

update: fellas think have figured out now, still apprecate if maybe if solid:

1)

yui().use('node', function(y)      var node = y.one(".smallimage")  y.one(".smallimage").get('parentnode').addclass("small"); }); 

2)

yui().use('node', function(y)      var node = y.one("img[src*='big']")  y.one("img[src*='big']").get('parentnode').addclass("big"); }); 

thanks!

your solution correct, function says using y.one affect 1 element. if have multiple images should use y.all.

also, keep in mind can inside 1 yui().use() call.


Comments