Reputation: 873
I am trying to load a portion of a page using jquery .load(), the the problem is, the div that I am trying to select is a variable
$('#additemsubmit').click(function(event){
event.preventDefault();
var location = $(this).parent();
var reload = '#' + $(this).parent().attr('id');
$(location).load("/index.php reload");
});
It seems I cant use variables for "location" and "reload"
Upvotes: 1
Views: 803
Reputation: 887225
You need to use string concatenation to pass a selector to .load()
:
$(this).parent().load("/index.php#" + $(this).parent().attr('id'));
Upvotes: 0
Reputation: 83358
I think this is what you're looking for.
var reloadId = '#' + $(this).parent().attr('id');
$.get("/index.php", function(response) {
$(location).html($(response).find(reloadId));
});
Upvotes: 3