CSS and targeting: img "title=this thing here" attribute
Can CSS be used to change the title attribute in this img tag to something more pleasant than P10305...? All the images I need to target are in tables (as shown below)
I would like to change all ima开发者_如何学Cge title attribute in a website to the name of the company. Is it possible?
<td><img border="0" title="THIS THING HERE" src="http://the website I'm working on.jpg" /></td>
Many thanks Mike
This isn't possible with CSS, as CSS only affects styles. What you're asking for is a content change.
The change you want is possible with Javascript, however. If you happen to be using Prototype, it's pretty easy:
$$('td img').each( function( image ) { image.title = "Company Name" } )
jQuery should make this similarly easy too.
Hope that helps!
That can be slimmed down a bit:
$('td img').attr('title', 'value');
jQuery will select all img
inside a td
and apply that attribute, no reason to have a .each
in there.
not using strict css. However jQuery, and other javascript methods can be used to select that image and change it's title attribute.
$('td img').each(function() { $(this).attr('title', 'value') });
gives you a rough idea of how to use jquery to do this.
Check out the documentation to get a better idea: http://docs.jquery.com/
精彩评论