I need to toggle two images by clicking on the parent a tag.
here is my JavaScript
$("#VerColMenu > li > a").click(function() {
var src = ($(this).children()[0].attr('src') === 'img/plus.png')
? 'img/minus.png'
: 'img/plus.png';
$(this).children()[0].attr('src', src);
});
but nothing happens here.
Attaching
[0]to a jQuery object retrieves the under-lying DOM object. Along with the above/below answers, you can also use.first()to get the first element in a jQuery array set:DEMO
This of course does have to be wrapped in
$(document).ready()or something similar.