JQuery Ajax Help

I have a page on my site that is currently loading html via ajax. JQuery:

$(document).ready(function() {
$('.projects a').click(function(event) {
    $('#work').load(this.href);
    event.preventDefault();
});

});

and html:

<div class="projects">
    <a href="work/link.html" title="blah" id="blah">blah</a>

    <a href="work/link1.html" title="blah" id="blah">blah</a>

    <a href="work/link2.html" title="blah" id="blah">blah</a>
</div>

this works great, but my requirements have changed. I would like to highlight a specific area of ​​the page that I load in the #work div. So I would like to say when the .project a button is pressed, load the contents of the #this div from this.href to #work. Can someone point me in the right direction?

+3
source share
2 answers

Take a look at the Downloading Page Fragments section . You can target sections of the loaded page by adding a selector to the url string.

.load(), $.get(), . url. , jQuery, .

$('# result'). load ('ajax/test.html #container');

, ajax/test.html, jQuery , . , .

$('#work').load(this.href + ' #this');
+6
$(document).ready(function() {
    $('.projects a').click(function (event) {
        jQuery.get(this.href, function (response) {
            $('#work').empty().append($(response).find('#myDiv'));
        });
    });

    event.preventDefault();
});
0

Source: https://habr.com/ru/post/1743175/


All Articles