Finding matched classname in jQuery

后端 未结 4 1708
执念已碎
执念已碎 2021-02-13 18:54

I have a series of image thumbnails in a page. They are created using css sprites.

4条回答
  •  离开以前
    2021-02-13 19:20

    You could use a Regex, but using split and indexof will be understood by more programmers. Also for something so simple, maybe better to avoid Regex.

    In the event handler use the jQuery normalized Event object:

    $("[class^=galleryImg]").click(function(Event) {
        var classAttribute=Event.target.className
    
        var classes=classAttribute.split(" ");
    
        for (var i=0;i

提交回复
热议问题