How to iterate through jQuery elements

前端 未结 2 1475
耶瑟儿~
耶瑟儿~ 2021-01-29 07:08

I want to be able to see what\'s inside the tags that jQuery finds. How come the following doesn\'t work?

 $(\"div.UIImageBlock_Content.UIImageBlock_ICON_Content         


        
2条回答
  •  逝去的感伤
    2021-01-29 07:19

    • $this => $(this)
    • .html => .html()

    So this should do it:

    $("div.UIImageBlock_Content.UIImageBlock_ICON_Content").each ( function() {
         alert($(this).html());
     });
    

    Note that html() function just uses the innerHTML property, so it can be a lot simpler:

    $("div.UIImageBlock_Content.UIImageBlock_ICON_Content").each ( function() {
         alert(this.innerHTML);
     });
    

提交回复
热议问题