Skip to content Skip to sidebar Skip to footer

Stripping Html From Jquery Load() Result

This is a followup to the solution for this question. I am using jQuery's load() function to pull a headline within a div tag from one page to another within my site. This works wo

Solution 1:

Navigate down one more level in your .load selector

a.load(a.attr('linked_path') + ' #news_header');

If your news_header id isn't unique, it isn't valid to select by that id (ID's must be unique!)

To get around that issue, use this:

a.load(a.attr('linked_path') + ' #' + a.attr('linked_div') + ' div');

Edit:.load actually includes the targeted element when appending html instead of appending the target element's children. I would move to using $.get().

$.get(a.attr('linked_path')).done(function(html) {
    a.text($(html).filter("#news_header").text());
});

Post a Comment for "Stripping Html From Jquery Load() Result"