How do I pass a variable (url) and ID into a jQuery .load function?

34 Views Asked by At

I want to get the url of the product clicked and then load only a certain div of the product page in a sidebar

I the below code works id I remove the + '#product-description'

$(function(){
    jQuery(document).on("click",".test-click",function(e){
      e.preventDefault();
      var el = jQuery(this);
      alert(el.attr("href"));
          $('#content').load(el.attr("href") + '#product-description');
    });
});
1

There are 1 best solutions below

0
Sgt AJ On

According to jQuery .load documentation here, you need one or more spaces between the URL and the tag, so try $('#content').load(el.attr("href") + ' #product-description');