Html jquery.load, dynamic file names

I got a menu made with li / a and I got jquery.load working with this. when I click on the link to which it is loading without updating the contents of the page in the div. but what is the best way to add the file name that should be loaded into the attribute?

this will load the page with the original link: 127.0.0.1/filetobeloaded.html for example. <a href="filetobeloaded.html">test</a>

but if I do <a href="#" rel="filetobeloaded.html">test</a>, I consider this to be the wrong attribute = /.

so what attribute should i use for this?

Congratulations, Stefan.

+3
source share
3 answers

href, . .click return false. .

<a href="filetoload.html" class="ajaxLinks">MyLink</a>

$('.ajaxLinks').click(function() {
    // do something with this.href       

    return false;
});

href javascript.

+1

href. javascript.

<a href="yourpage.html" class="ajaxLink">Link 1</a>

Script

$(function(){

 $("a.ajaxLink").click(function(e){
    e.preventDefault() //to prevent the normal behaviour of a tag
    $("#yourContentdiv").load($(this).attr("href"));
 });

});
+1

If you use, it’s good to use href or rel, in another element you should use data-like data-load = "url"

click the button to just trigger the event, therefore:

$('a').click(function(ev) {
  // load stuff here using $(this).attr('href')
  ev.preventDefault();
  return false;
}
0
source

All Articles