Blog

Manipulate an Element from an Attribute and Value Pair
Posted on January 9, 2012 in jQuery by Matt Jennings

The code below grabs an img tag with a width="434" attribute and value pair, goes up to the parent tag – a td – and adds a class of .green-bg to the td tag. See http://api.jquery.com/attribute-contains-selector/ for more details.

This code was used throughout http://www.friendlysmiles.net/ to fix an IE bug.

[js]
$(document).ready(function(){
/*
Add green background behind header images
**Fixes a bug in IE7-8
*/
$(‘img[width=”434″]’).parent(‘td’).addClass(‘green-bg’);
});
[/js]

Tags:

Leave a Reply

To Top ↑