How to add element in element using jquery
I have a code like this:
<p>Nuno</p>
<p>Eimes</p>
How i manipulate into like this:
<p><a href="name/Nuno">Nuno</a></p>
<p><a href="name/Eimes">Eimes</a></p>
i tried
var name=$(this).text();
$( "p" ).each(function() {
$(this).prepend('<a href="id/'+ $(this).text() +'"> ');
$(this).append("</a>");
});
but it result:
<p><a href="id/Nuno"> </a>Nuno</p>
<p><a href="id/Eimes"> </a>Eimes</p>
the <a> is not inside $('p').text(); also if i change to name. it didn't
show the value.
No comments:
Post a Comment