I’m trying to make a simple script that adds rel=”lightbox” to links with .jpg or .gif in the href. Can someone help me? I can’t see the mistake. Thank you.
<script type="text/javascript">
$('a[href*=".jpg"]').each(function() {
$('a[href*=".gif"]').each(function() {
$(this).attr('rel','lightbox');
});
});
</script>
You’re targeting links with href attributes that contain BOTH ‘.jpg’ AND ‘.gif’. Try targeting links with href attributes that END WITH EITHER ‘.jpg’ OR ‘.gif’:
Update
To run the script when the DOM is ready, attach the function to the domready event: