Load only part of the page using jquery

I have a wordpress site and you want to load my pages using jquery. I want to load div content, so I pass this url like this:

var url = $(this).attr('href') + "#content";

Now when I try to load the page using ajax, it loads the url without the #content part. Now it loads the full page into my div, and not just the part that I want.

Maybe this has something to do with my .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# RewriteRule ^index\.php$ - [L]
RewriteRule ^(index\.php/?|intro.html)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Any ideas?

+5
source share
3 answers

You can use something like this:

$.get(url,function(response){
 content = $("#content",response);
 $('#newContentHere').append(content);
});
+4
source

I think you need a space in front of the hash.

Here is an example .load () from jQuery docs:

$('#b').load('article.html #target');

so in your case:

var url = $(this).attr('href') + " #content";

$('#containerDiv').load(url);
+4
source

, ajax jquery.

, div, , "", :

success: function(data) {
    $("content").html($(data).find("results").html());
}
0

All Articles