Home  >  Article  >  Web Front-end  >  jquery pop-up plug-in colorbox binding method to dynamically generate elements_jquery

jquery pop-up plug-in colorbox binding method to dynamically generate elements_jquery

WBOY
WBOYOriginal
2016-05-16 16:43:471718browse

Colorbox is a very easy-to-use pop-up plug-in for jquery. It has rich functions and a good user experience.

colorbox official website: http://www.jacklmoore.com/colorbox/


I just encountered a problem when using colorbox, which I had not noticed before.

I used to talk about using this plug-in in static HTML elements, but today I found that it cannot be used when binding dynamically generated elements.

The conventional usage is as follows:

Copy code The code is as follows:

Copy code The code is as follows:

$(document).ready(function(){ 
$(".test").colorbox();
});

The above method only applies to static elements. If you want to bind colorbox effects to dynamic elements, you have to use the following method:

We assume that the tag in the above HTML is a dynamically generated element, then the js has to be written like this:

Copy code The code is as follows:

$(".test).live('click',function(){
$.colorbox({href:$(this).attr('href'), open:true, height:'100%'});
Return false;
});

Okay, the problem is solved perfectly. Hope it helps.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn