jQuery first child of “this”

后端 未结 10 1158
暖寄归人
暖寄归人 2020-12-04 05:48

I\'m trying to pass \"this\" from a clicked span to a jQuery function that can then execute jQuery on that clicked element\'s first child. Can\'t seem to get it right...

10条回答
  •  日久生厌
    2020-12-04 05:49

    please use it like this first thing give a class name to tag p like "myp"

    then on use the following code

    $(document).ready(function() {
        $(".myp").click(function() {
            $(this).children(":first").toggleClass("classname"); // this will access the span.
        })
    })
    

提交回复
热议问题