0
To get a list of all the Ids of the elements that have class that starts with post-
, just do something like this:
const postIds = Array.from(
document.querySelectorAll('article[class*="post-"]')
).map((el) => el.id);
console.log(postIds);
<article id="1" class="post-1"></article>
<article id="2" class="post-2"></article>
<article id="3" class="post-3"></article>
<article id="4" class="post-4"></article>
<article id="5" class="post-5"></article>
Note that if you can ensure that the class post-
always come first, you can change the selector article[class*="post-"]
for article[class^="post-"]
to have a small gain in performance.
you want to get the id attribute value or the element with id 72?
– Vinicius.Silva
I think you can take it this way: const element = Document.getElementById('Representatives-list'). Children[0];
– cezar
getElementById
obtains only the elements with id specified in that caserepresentatives-list
is a class and not an ID, so you can usedocument.querySelectorAll('.type-representantes')[0]
– Vinicius.Silva
Out of curiosity, how does PHP generate this page? It is not easier to use the function
get_the_ID()
to get the post id?– Woss