Therefore, you can use Element.matches() to determine if an element contains a class. How to perform and shine in a team when the boss is too busy to manage. W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Is there a specific reason why you added spaces before and after? When searching with [data-x=], watch out, it doesn't work with jQuery.data(..) setter: I know the question is about JQuery, but readers may want a pure JS method. Is there a reason why you'd want to use classlist instead of index of e.className? Sure, you just have be aware of what you are testing. Introduction to jQuery find child. Where the former extension searched on a key-value pair, with this extension you can additionally search for the presence of a data attribute, irrespective of its value. http://james.padolsey.com/javascript/a-better-data-selector-for-jquery/, Continuous delivery, meet continuous security, Help us identify new roles for community members, Help needed: a call for volunteer reviewers for the Staging Ground beta test, 2022 Community Moderator Election Results, Jquery Find element with specific data attribute, Using jQuery variables to select data-* HTML 5 elements. Connect and share knowledge within a single location that is structured and easy to search. The .then() method takes up to two arguments; the first argument is a callback function for the fulfilled case of the promise, Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks or registered trademarks of their respective holders. To get the value of a script element, use the .html() method.. As of jQuery 1.4, the .text() method returns the value of The matching text can appear directly within the selected element, in otherwise I find them as interesting as a mosquito. you could just use /^class_name_you_are_searching_for$/.test(myElement.className), I wrote that too fast. Maybe useful for others that find this thread. For instance, when the mouse pointer moves over the Inner element in this example, a mouseover event will be sent to that, then trickle up to Outer.This can trigger our bound mouseover handler at inopportune times. How jQuery Add Attribute to an HTML element This works on all current browsers and there are polyfills to support older browsers too. if similar elements exist in the array then the elements are Continuous delivery, meet continuous security, Help us identify new roles for community members, Help needed: a call for volunteer reviewers for the Staging Ground beta test, 2022 Community Moderator Election Results, Loop Through and Hide Elements Containing a String, jQuery - change font-weight of specific text with same class name, Select only the innermost div with specific text. How to target specific attribute with a certain value in jQuery? The HTML markup for the select list is essentially identical. You can use .attr() to both change an attribute value by specifying two parameters, or get the value by specifying one. Contrast this with .position(), which retrieves the current position relative to the offset parent. return all elements that are descendants of an