Place ID within a TITLE

0

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?

    
asked by anonymous 23.10.2015 / 01:29

2 answers

1

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>
    
23.10.2015 / 01:52
0

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>
    
23.10.2015 / 01:49