jquery - Want to append tooltip content in <li> element -


<div>   <ul>     <li>this first point</li>     <li>this second point <a href="http://" title="this more tooltip">more</a></li>   </ul> </div> 

i want append anchor tags title text within li element using jquery plain text no hyperlinks.

for example, after processing li element be

<li>this second point more tooltip</li> 

this how (comments in code explain happening):

$('li').each(function() {  // loop through each li - can change selector match needs    var li = $(this),        anchors = li.find('a'); // in case there multiple anchors?        anchors.each(function() {      var anchor = $(this),          title = anchor.attr('title');            if (typeof title !== typeof undefined && title !== false) { // if if title attribute exists remove anchor        anchor.after(title);  // place title after link keeps it's place in li (in case there text after link).  if want text @ end of li use li.append(title);        anchor.detach();   // remove anchor - move after if statement if want remove anchor , it's text regardless of whether or not has title.  if want keep text in anchor, remove line altogether      }    });        // li.text(li.text()); // remove other html within li (optional)  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div>  <ul>      <li>this first point</li>      <li><strong>this second point</strong> <a href="http://" title="this more tooltip">more</a></li>  </ul>  </div>


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -