0

I want a javascript code which will select the element whose class name begins with the string "bzeytq". Maybe the full class name is "bzeytqsXAl0a4TF2EK1PC _3cTEY2txA4EJKTiaTADaE", but I want to store the starting of the class name as a search variable, and use the search variable to find elements by class name.

Something like this :

search_str = "bzeytq"
itemName = document.querySelectorAll(search_str )[0].innerText;

It should select the element with full class name as "bzeytqsXAl0a4TF2EK1PC _3cTEY2txA4EJKTiaTADaE"

  • Possible duplicate of [Is there a CSS selector by class prefix?](https://stackoverflow.com/questions/3338680/is-there-a-css-selector-by-class-prefix) – le_m Jun 02 '17 at 23:03
  • Can you confirm whether or not the suggested duplicate fully addresses your question? – le_m Jun 02 '17 at 23:03
  • `querySelectorAll('[class^="'+search_str+'"]')` – adeneo Jun 02 '17 at 23:03
  • a) Highly recommend using jQuery - makes this kind of thing a lot easier. b) Why not have 2 classes - one for the search term - e.g., "bzeytq" and another for the full detailed class name? Or have the full detailed item be the ID? The general concept is to have the class name be repeated - which makes it great for group searches (in jQuery - $('.bzeytq')....) and to have the IDs be truly unique. – manassehkatz-Moving 2 Codidact Jun 02 '17 at 23:08

1 Answers1

1

Use JQuery to target specific class with following syntax $('.className')

Wolf
  • 21
  • 4