Hisfantor Hisfantor - 1 year ago 125
jQuery Question

readout data- atribute with js

I whant to write Links in the data atribute and to save up code lines I whant to create the links with a standart text and the href of course with js/jquery

var mdUrl = $(".md")this.data('md');
$(this).html("YES click <a href='" + mdUrl + "'>here</a>");

Answer Source

If i understand it right, you want sth like this

<div class="md" data="coolsite.com">content.</div>

converted to:

<div class="md">content <a href="coolsite.com">click here</a></div>

You could do this with the following js:

   md.innerHTML=md.innerHTML+"<a href='"+md.data+"'> click here</a>";

This loops trough the elements with the "md" class and adds a link to their inner html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download