开发者

Display the same title text for all elements of the same class?

开发者 https://www.devze.com 2023-02-23 18:02 出处:网络
Lets say I want to display tool tips for links using the title attribute: <a class=\"editcommand\" title=\"Edit\" ...>

Lets say I want to display tool tips for links using the title attribute:

   <a class="editcommand" title="Edit" ...>

Is there a way to specify the 开发者_如何转开发title text for all elements of the same class using CSS, so I don't have to repeat it within each element?


CSS is only for the content of the style="" attribute, not other HTML tags. This sounds like a job for Javascript. If you're using jQuery here's an example:

$('a').attr('title', 'My universal title');


Unfortunately, no, CSS does not provide that ability. Since title is an HTML attribute (besides the <title> element of course), it's up to the markup structure (DOM) to define it, not the style (CSS).

With JavaScript it's just a matter of attaching the attribute to a set of DOM elements with that class. But again, that's modifying the DOM elements themselves, not their style properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消