admin管理员组文章数量:1356379
I'm having a problem similar to this: JavaScript not working inside AJAX loaded DIV but my problem is that I don't have any event to bind to. I have this:
$('[title]').colorTip({color:'yellow'});
binding all elements with 'title' attribute to that object. It works fine on page reload. But on elements from AJAX call the story is different, it displays like the javascript doesn't exist. I know to bind elements to other events from AJAX using live()
, but how do I bind elements that don't have 'events'?
I'm having a problem similar to this: JavaScript not working inside AJAX loaded DIV but my problem is that I don't have any event to bind to. I have this:
$('[title]').colorTip({color:'yellow'});
binding all elements with 'title' attribute to that object. It works fine on page reload. But on elements from AJAX call the story is different, it displays like the javascript doesn't exist. I know to bind elements to other events from AJAX using live()
, but how do I bind elements that don't have 'events'?
2 Answers
Reset to default 9you have to re-bind the tooltip after the ajax call.
$( document ).ajaxStop( function() {
$('[title]').colorTip({color:'yellow'});
});
Or as suggested by jbabey, you might use the plete callback to re-bind the tooltip (simplified version from here):
$(
function(){
// Get a reference to the content div (into which we will load content).
var jContent = $( "#content" );
// Hook up link click events to load content.
$( "a" ).click(
function( objEvent ){
var jLink = $( this );
// Clear status list.
$( "#ajax-status" ).empty();
// Launch AJAX request.
$.ajax(
{
// The link we are accessing.
url: jLink.attr( "href" ),
// The type of request.
type: "get",
// The type of data that is getting returned.
dataType: "html",
plete: function(){
console.log("finalized ajax request");
//re-bind the tooltip
$('[title]').colorTip({color:'yellow'});
},
success: function( strData ){
console.log("ajax success");
console.log(strData);
// to something with the received data
jContent.html( strData );
}
}
);
// Prevent default click.
return( false );
}
);
}
);
Based upon your ment I included the following: You also have to make sure you bind the tooltip on page load:
$( document ).ready( function() {
$('[title]').colorTip({color:'yellow'});
});
You can create a change event on the element.
$('title').live('change', function () {
whatever you want to do here
})
Then you would just trigger the change whenever you want the attribute to take effect.
$('title').trigger('change');
本文标签: javascriptJQuery ToolTip Not Working After AJAX callStack Overflow
版权声明:本文标题:javascript - JQuery ToolTip Not Working After AJAX call - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743987796a2571588.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论