Binding click to a repeated div ID

后端 未结 7 2118
孤独总比滥情好
孤独总比滥情好 2021-01-23 10:33

I\'m trying to create a div popup gallery type thing. But I\'m having an issue with my approach.

I have a few linked thumbnail images, which link to the lar

7条回答
  •  半阙折子戏
    2021-01-23 11:11

    According to documentation, your id has do be unique in the page. If you want to have more HTML elements with that style (for exapmle), use class.

    id = name [CS]:
    

    This attribute assigns a name to an element. This name must be unique in a document.

    class = cdata-list [CS]:
    

    This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.

    
    
    
    

    Then when you select with jQuery that class you use $(".galImage").

    $('.galImage').click(function(e){
        e.preventDefault();
        alert($(this).attr("href"));
    });
    

    Updated your jsFiddle.

提交回复
热议问题