开发者

Using jQuery with JSF auto-generated ids (issue with ":")

I read this post Handling a colon in an element ID in a CSS selector which outlines how to select a known id that contains a colon.

What I would like to do is create a JSF list that contains images. Then using jQuery I would like to select each image and read in the id. Is this pos开发者_如何学Gosible without writing some code to replace the colons?


Use jQuery to iterate over each individual img element. Assuming that your ul element has the id wx:yz:

// Use jQuery to select all images within
var imgs = $('#wx\\:yz img');

// Iterate over each one and give the image ID to the library
// only if the image actually has an ID.
imgs.each(function() {
    if(this.id && this.id.length) {
        nameOfYourLibraryFunction(this.id);
    }
});


It's safer to use classes instead of IDs when using JSF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜