Im new to jQuery and i'm trying to convert all my phone class to have an anchor with an href:
What I have
<div class="phone">111-111-1111</div>
<div class="phone">666-555-4444</div>
What I want
<div class="phone"><a href="tel:111-111-1111">111-111-1111</a></div>
<div class="phone"><a href="tel:666-555-4444">666-555-4444</a></div>
I am trying to do something like this, but I am pretty lost:
$('.phone').each(function(){
$(this).wrapInner('<a name="???' + $(this).html() + '" />');
});
To add href attribute to a link dynamically using JavaScript, we can set the link's href property. const a = document. getElementById("yourlinkId"); a.
To add a title in anchor tag in jQuery, use the prop() method. The prop() method is used to set properties and values of the selected elements.
I have a <span id="aa"> to enclose a link tag with href="#" as the url.
I think solution is there in your question only...
Have a look at this.
$('.phone').each(function(){
$(this).wrapInner('<a href="tel:' + $(this).html() + '" />');
});
FIDDLE Hope this is what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With