Reputation: 11642
I would like to change href
using jQuery Mobile, I tried a some code examples like:
$("a[href='http://www.google.com/']").attr('href', 'http://www.live.com/');
<li><a data-ajax="false" href="http://www.google.com" >Navigate</a></li>
and
$("#address").append("href", "http://cupcream.com");
<li><a data-ajax="false" id="address" href="http://www.google.com" >Navigate</a></li>
But nothing happens.
What can be wrong, aren't this some bug in jQuery Mobile?
Upvotes: 0
Views: 4823
Reputation: 7599
If you do not have the data-ajax="false"
then the link will not be changeable via the jquery attr function. I see that you have it, but I'm mentioning it for future searches.
Once you have that, you can change the link like so: $('a[href='http://www.google.com/']').attr('href', 'http://www.live.com/');
I suggest ensuring that your selector is working as expected by doing a 'hide()' on a test case as well.
Upvotes: 1
Reputation: 1024
Use .attr()
method, not .append()
$("#address").attr("href", "http://cupcream.com");
Upvotes: 0
Reputation: 105
Changing just href
attibute did not work for me. I had to change both, text and the attribute href
and that worked just fine. Tested on Chrome, Firefox and IE10.
$('#campuslink').text('http://www.google.com');
$('#campuslink').attr('href','http://www.google.com');
This fixed the issue for me.
Upvotes: 1
Reputation: 368
You need to add to your "a" element the attribute rel="external"
or data-ajax="false"
, in order for the links to not be managed via Ajax.
Official Documentation here.
Also look at JQuery Mobile History on data-ajax=false
Upvotes: 1