Issue
I have a list of links. And I want that link texts inserts as span span data-hover names. Please tell me how can i do this. Thanks!
What i have:
<a href="#">Paris</a>
<a href="#">London</a>
<a href="#">Berlin</a>
What i want:
<a href="#"><span data-hover="Paris">Paris</span></a>
<a href="#"><span data-hover="London">London</span></a>
<a href="#"><span data-hover="Berlin">Berlin</span></a>
Solution
The below code will work -
var links = document.getElementsByTagName("a");
for (i = 0; i < links.length; i++) {
links[i].innerHTML = '<span data-hover="' + links[i].innerHTML + '">' + links[i].innerHTML + '</span>'
}
<a href="#">Paris</a>
<a href="#">London</a>
<a href="#">Berlin</a>
Answered By - Archit Gargi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.