Looking to move the class name of an image to it’s containing figure element using jQuery…
<figure class="wp-caption">
<img class="imghvr-hinge-up" src="image.jpg">
<figcaption >A sample caption</figcaption>
</figure>
In particular I would like to move any img tag class name beginning with ‘imghvr-‘ to it’s containing figure, if that containing figure has the class name ‘wp-caption’. The result would look like the following…
<figure class="wp-caption imghvr-hinge-up">
<img class="" src="image.jpg">
<figcaption >A sample caption</figcaption>
</figure>
Hope that makes sense!) Any help would be greatly appreciated!
You could do it like this
Something like that. I didn’t test.
Edit: As always there is smarter than me ^^
You can utilize
.closest()
,.addClass(function(){})
,.is()
Alternatively, using
.toggleClass()
,.is()
,.find()
,.attr()