I need to put an id in an example title
<div title="<span id=""></span>"> </div>
But I did not get results, how can I do this?
I need to put an id in an example title
<div title="<span id=""></span>"> </div>
But I did not get results, how can I do this?
You can use attr()
to access the title attribute and put the new value, and deposit it to get it again, eg:
$("div").click(function() {
$("div").attr('title', 'Meu Título'); // coloca a informação na div
alert($("div").attr('title')); // recupera o valor
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><divtitle="">Clique na DIV</div>
It is not possible to place a id
or class
within a title
, or even HTML. The title=""
attribute is only for specify additional information for an element.
However if your intention is to customize the title
attribute, you can do it as follows:
#meuTitulo {position: relative;}
#meuTitulo[title]:hover:after {
content: attr(title);
color: #fff;
position: absolute;
left: 0;
top: 100%;
padding: 4px 8px;
z-index: 20;
white-space: nowrap;
background-color:royalblue;
}
<a href="#" id="meuTitulo" title="Olá, eu sou um link!">StackOverflow</a>