quotation marks around the attribute value of an element

Javascript has a function called querySelector, which is used to get the dom object of an element based on some condition specified as the parameter of the function, such as

var ele=document.querySelector(‘[someattribute=somevalue]’);

The above statement get the first element which has an attribute someattribute and the attribute value is somevalue. If there is no such element with that attribute or the value of the attribute is not somevalue, the function will return null.

The attribute of an element can be specified as <someelement someattribute=”somevalue”> or <someelement someattribute=somevalue>(note that the quotation marks around the attribute value are missing) . For both specifications, the element can be retrieved successfully by document.querySelector(‘[someattribute=somevalue]’) or document.querySelector(‘[someattribute=\”somevalue\”]’), i.e., the quotes around the attribute value can be ignored.

Comments are closed, but trackbacks and pingbacks are open.