I'm trying to refresh just one part of my page when a user clicks a 'clear' button, currently I'm using a bit of code I hacked off another answer I found on here:
$('.clear').click(function () {
$.ajax({
url: "",
context: document.body,
success: function (s, x) {
$(this).html(s);
}
});
});
This reloads the whole document body, how do I target a particular div or class?
context: document.body.somediv?
Try
Can also access div by its class like
Have u tried using of context
In success
Hi if you want that ajax output reflect on a particular div, Please make sure that div has Id or class so we can easily trace that on DOM. Suppose that div has class
content-output
then following script will work for you.If you want to load only particular div via Ajax then use jquery load event like this
If you to perform some kind of action then add function inside load event like this
jQuery API about the
context
option:So, the
context
option is to set the scope of thethis
object in the callback functions. By default it is the ajax object, with the current configuration:If you wish to target a specific section to load the response in, you can just use jQuery to find the element and put the response in that element,
context
is not relevant for you:However, you can use
context
to make the configuration a bit easier to understand, like so:If you now want your ajax response to be loaded somewhere else on the page, you just have to change the selector on the
context
parameter.You can use DIV id or class name to target a particular div element.
If I understand correctly,you can simply call .load() from a click event and pass it the href of the link:
see the demo