$("#button").click(function () {
//debugger;
if ($("img[id=image][src:contains(Grass)]"))
$("img").attr({ src: "/Content/images/Spring.jpg", alt: "Spring" });
else
$("img").attr({ src: "/Content/images/Grass.jpg", alt: "Grass" });
});
<a href="/Content/images/Grass.jpg"><img src="/Content/images/Grass.jpg" alt="image" id="image"/></a>
<input type="button" id="button" name="button"/>
I have simple form with image and button, i want on each button click image getting changed. The logic is very simple. By default image src = /Content/images/Grass.jpg When i click button first time image getting changed, but when i am click second time it is does not changed back. I check in debugger and find out that condition $("img[id=image][src:contains(Grass)]") always true. But after first button click shouldn't it became false then?
if i declare
var img1 = $("img#image[src:contains(Grass)]");
var img2 = $("img#image[src:contains(Grass2)]");
var img3 = $("img#image[src:contains(blabla)]");
each img1.length = 1 img2.length = 1 img3.length = 1 Why?
but
var img1 = $("img#image[src*='Grass']");
var img2 = $("img#image[src*='Grass2']");
var img3 = $("img#image[src*='blabla']");
each img1.length = 1 img2.length = 0 img3.length = 0 it is what was expected.
Does it means that src:contains(text) and src*=text is so different?