Get the current jQuery selector string?

2020-01-29 08:04发布

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

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

Would like to output my_selector p within my script. How can I access this string?

7条回答
Luminary・发光体
2楼-- · 2020-01-29 09:08

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
查看更多
登录 后发表回答