I’m trying to do the following in jquery but can’t make it work .
I want to select all the DIV tags that have a custom attribute called NODE_ID that have a value of 49_3. then select the and change the src attribute to a different image.
Here’s the HTML:
<div style="display: block;" id="71_7_sub_p_div" node_id="49_3">
<span>
<img src="../images/maximize.png"> Greenfield Industrial Park
</span>
</div>
Here’s the script:
<script type="text/javascript">
$(document).ready(function(){
$("div[node_id='49_3']:has(img)").attr("src","../images/folder_closed.png");
});
</script>
Any ideas are appreciated. thanks.
That should work but I would suggest that you use CSS for these images rather than use javascript to switch the src.
CSS
Javascript:
The benefit of doing it like this is that you can easily manage the different states styles in the CSS and don’t have to dig through the javascript when you need to change the url to the image. Also it gives you an easy way to figure out the state of the “folder”.