Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  73] [ 4]  / answers: 1 / hits: 52565  / 8 Years ago, wed, april 13, 2016, 12:00:00

I'm trying to reload particular element on button on click using jQuery, but when I click the button, the entire page gets loaded in this element. I have tried the following code which loads the entire page in this element. I want to load only particular element.


$(document).ready(function() {
$("#button").click(function() {
$("#demo").load(location.href + "#demo");
});
});

<div id="example">
<p id="demo">hi</p>
<button id="button" type="button">press</button>
</div>

More From » jquery

 Answers
54

You can use load() with selector.



$(#demo).load(location.href +  #demo); // Add space between URL and selector.
^


This will load only the #demo element from the location.href URL.


[#62580] Monday, April 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carolinabritneyp

Total Points: 75
Total Questions: 102
Total Answers: 105

Location: Armenia
Member since Fri, Apr 16, 2021
3 Years ago
;