Selecting an ID with a colon in it with jQuery

前端 未结 4 1177
南笙
南笙 2020-11-29 09:46

I\'m working on a pre-written module for a site, and I need to target an element with the id test:two. Now, this element has a colon in it, so jQuery is presuma

4条回答
  •  佛祖请我去吃肉
    2020-11-29 10:28

    Try using an attribute selector

    $(document).ready(function() {
        $('div[id="test:two"]').each(function() {
           alert($(this).text());
        }); 
    });
    

    Fiddle: http://jsfiddle.net/zbX8K/2/

提交回复
热议问题