开发者

javascript, colorbox - dynamically get ID

I am trying to grab an id dynamically using to load up content in a modal window, but I am having difficulty grabbing the id.

Here is the example I posted up on JSFiddle

The divs with class ticket_details and anchor tag with class dialog_link is generated dynami开发者_高级运维cally using PHP.

If you need more clarification, let me know! Thanks for your help.


The following selector var e = $('.ticket_details'); returns a list of divs. What you need to do is iterate through all of the returned divs and do whatever you want, something like this: $('.ticket_details').each(function () { console.log($(this).attr('class')); });


Both the comment by tjameson and the answer by Ali are spot-on.

Although it's not technically incorrect to assign classes that are unique, it's also not a best practice. (I'm thinking about future maintainers here.) The ID element is more to your purposes and will simplify your getting the ID with JQuery.

If it's possible, have the PHP gen unique IDs for the DIVS while still classing them as 'ticket_details' as tjameson suggests.

PS (to moderators) this question has little to do with the ColorBox pulgin and everything to do with Jquery selection.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜