Get the current jQuery selector string?

前端 未结 8 2004
北恋
北恋 2020-12-01 18:00

When calling a custom plugin, how can I get the current selector string?

$(\'my_selector p\').my_plugin();

Would like to output my_se

8条回答
  •  忘掉有多难
    2020-12-01 18:31

    Best workaroud is

    function mySelector(selector) {
        return $.extend($(selector),{"selector":selector});
    }
    

    this returns classic jquery object as $() would

    mySelector(".myClass")
    

    and this returns string of the selector

    mySelector(".myClass").selector
    

提交回复
热议问题