Basically I am trying to search the page when it loads for the string “Quantity in Stock:7″. If it cannot find this string it will replace the [img id=”product_photo” src=”bleh.gif”] with the image listed in the source below. If the string is found then I do not want the image to bereplaced.
What we want is that if the quantity of a product on our site does not equal 7 we want to display a deposit taken image instead of the product image. However the code below is not working for me. I am not asking for a magic solution (however that would be nice) even a push in the right direction would be greatly appreciated.
Below is the code I have come up with and I am a javascript novice trying to learn as I go so forgive me if the code is not right. I have pieced this together using my limited knowledge and assistance from other stack overflow articles.
<script type="text/javascript">
window.onload = function() {
var foundin = $('*:contains("Quantity in Stock:7")');
If (foundin != "Quantity in Stock:7") {
$("#product_photo").attr("src", "/v/vspfiles/templates/Raceweek/images/dt_image.gif");
}
};
</script>
Thanks in advance,
Camo
$('*:contains("Quantity in Stock:7")')does not return a string. It returns a jQuery set of matched elements.In your case, if it found your string, then the matched set will not be empty. So we’ll check the length of the matched set:
Note: you should not have to run that
containson the whole page! Run it only on the element that holds the quantity.