Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove ajax call from regular links with jQuery Mobile

Using jQuery Mobile I would like to disable the ajax call on links within a specific part of the DOM.

I do not want to put a

data-ajax = false

every time I don't want to use the jquerymobile ajax.

For example, any link that is a child of 'content':

<div class="content">
    <a href="http://externalwebsite.com">External Link</a>
</div>

I would like to add the 'data-ajax = false' onto every link that is a child of 'content'

Is there a way to do this with jquery?

like image 349
cusejuice Avatar asked Apr 25 '12 16:04

cusejuice


2 Answers

If you want to disable the ajax link behaviour from an anchor tag, you can put rel=external in the link and the link will load without ajax and your url will then be usual.

http://jquerymobile.com/demos/1.0a4.1/#docs/pages/docs-navmodel.html

<a href="User/somepage" rel="external" />I wont be using ajax for navigation</a>

If you want to do this in jQuery for some a tags inside content div, you may try like this

$(function(){
  $(".content a").each(function(){
    $(this).attr("rel","external");
  });
});

Here is a sample http://jsfiddle.net/4WEBk/3/

The more Simplified version. (Thanks to tandu for pointing )

$(function(){
  $(".content a").attr("rel","external");
});
like image 194
Shyju Avatar answered Nov 09 '22 18:11

Shyju


$(".content a").attr('data-ajax', false);
like image 5
Explosion Pills Avatar answered Nov 09 '22 18:11

Explosion Pills