Andrés Orozco
Andrés Orozco

Reputation: 2661

Set title to an element with CSS

What I want to do is to apply a specific title to any element with a specific class.

HTML

<span class="br">BR</span>
<span class="dvd">DVD</span>
<span class="br">BR</span>
<span class="br">BR</span>
<span class="sc">Sc</span>

CSS

span{
    width: auto;
    height: auto;
    padding: 5px;
    color: white;
}
.br{
    background: blue;
}
.dvd{
    background: green;
}
.sc{
    background: black;
}

Example on JSFiddle

How can I set a title to any element with the class "br"? Is it better to do it with jQuery?

Upvotes: 0

Views: 3937

Answers (2)

swsa
swsa

Reputation: 225

$('.br').attr("title","your title attribute goes here");

Upvotes: 1

Jacques
Jacques

Reputation: 3774

Do it with jquery. CSS is a presentation language. It isn't designed to add content, aside from :before and :after

Jquery:

$('.br').attr('title','yourtitle');

Upvotes: 5

Related Questions