I repost the question (i deleted what i did before, because, my fault, i was not enough clear, i'm deeply sorry).
I have this var:
var telefono = $(this).find('Telefono').text();
This "Telefono" is a number, taken from a xml file, with a javascript. I don't post all the function, but if you think it helps, let me know.
I need to put this var inside a button. It's a button for a mobile website (in jquery), with the command "tel" (it uses the number beetween the { } to make a call):
< a target = "_blank " href = " tel:{{"telefono"}} " data-role="button" >
I don't find the right way to write the var in the button.
Can you help me?
You can do this :
$('a[href~="tel:{{telefono}}"]').attr('href', 'tel:'+telefono);
If you want something more generic, that is you want to replace {{telefono}}
in all your attributes href
, you could use this :
$('[href~="{{telefono}}"]').attr('href', function(i, v) {
return v.replace('{{telefono}}', telefono);
});
EDIT :
If you also want to change the content of the a
element, you can do this :
$('[href~="{{telefono}}"]').attr('href', function(i, v) {
return v.replace('{{telefono}}', telefono);
}).html(telefono);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.