check if element has class javascript

check if element has class javascript

if class equals element javascript. @KayceBasques: because we also add spaces to. classList.contains("class-name") Here's an example. In modern browsers, you can just use the contains method of Element.classList : If you want to use Element.classList but you also want to support older browsers, consider using this polyfill by Eli Grey. document.getElementById( "ak_js_1" ).setAttribute( "value", ( new Date() ).getTime() ); (adsbygoogle = window.adsbygoogle || []).push({}); 2016-2022 Makitweb, All rights reserved, Check class on a single element using JavaScript, Check class on multiple elements using JavaScript, How to Send GET and POST cURL request in CodeIgniter 4, How to add pagination using Yajra Datatables in Laravel 9, How to Add Remove package using Composer in Laravel, How to add Edit Delete button in Yajra DataTables Laravel, How to add Foreign key in migration CodeIgniter 4. Found footage movie where teens get superpowers after getting struck by lightning? onClick to get the ID of the clicked button, Find the closest ancestor element that has a specific class. Example: This example implements the above approach. rev2022.11.3.43005. Of course this is only a lookup for 1 simple element (/Image/g) but you can put all in an array like

  • is /LI/g,