Created
September 30, 2011 19:37
-
-
Save kapusta/1254761 to your computer and use it in GitHub Desktop.
jQuery addressable AJAX/HTML fragments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
url: "/some_path/foo.php", /* a url that returns a fragment of html */ | |
dataType: "html", /* ask for and expect html */ | |
success: function(html){ | |
var $fragment = $("<div/>") /* make a fragment (createDocumentFragment() won't work) */ | |
.html(html) /* put the html into the div so we can get at stuff in jQuery */ | |
.find("#some_id"); /* we can now .find() things! */ | |
/* if there's a <span id="some_id" data-foo="bar"></span> in out returned html, then... */ | |
console.log($fragment.data("foo")); /* ...logs "bar" */ | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment