I'm working on a website that is dynamically loading content in a DIV. Everything works fine except when the content contains a jquery plugin (f.e. a twitterfeed) the jquery plugin doesn't work..anybody knows how to get the plugins to work?
$(function() {
var newHash = "",
$mainContent = $("#main-content"),
$pageWrap = $("#page-wrap"),
baseHeight = 0,
$el;
$("nav").delegate("a", "click", function() {
window.location.hash = $(this).attr("href");
return false;
});
$(window).bind('hashchange', function(){
newHash = window.开发者_Python百科location.hash.substring(1);
if (newHash) {
$mainContent
.find("#guts")
.fadeOut(200, function() {
$mainContent.hide().load(newHash + " #guts", function() {
$mainContent.fadeIn(200, function() {
$pageWrap.animate({
height: baseHeight + $mainContent.height() + "px"
});
});
$("nav a").removeClass("current");
$("nav a[href="+newHash+"]").addClass("current");
});
});
};
});
$(window).trigger('hashchange');
});
If you use $.load with a selector ($(target).load("url #selector")), jQuery removes all SCRIPT tags from response.
Some solutions that come to my mind are:
- changing the back-end to return only the content required by the script
- do a $.get request, treat the reponse as plain text, do string manipulation to extract only the parts you need and then convert the result to DOM nodes. To do it right, a HTML parser is needed.
精彩评论