What does the dollar sign mean inside an attribute selector in jQuery?

不羁岁月 提交于 2019-12-04 23:12:51

The dollar sign

The first $ is a shorthand for the jQuery() function, the jQuery object constructor.

In other words, it's a variable called $ that's been assigned a function called jQuery, as can been seen in the unminified version of the jQuery source: window.jQuery = window.$ = jQuery;

The dollar-equals sign

The second $ is part of a jQuery selector called Attribute Ends With Selector . When used in an attribute selector, $= is a logical operator that literally means "true if the left-hand value ends with the right-hand value".

What this script actually does

Overall, this snippet first selects any element with an id attribute ending in scuba. It then retrieves the id value of the first element from the resulting jQuery object.

This code selects all DOM elements that have id attributes that end in scuba and returns their id values.

I'm pretty sure it's a better idea to include quotes around scuba, though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!