0
how should select the element from the DOM containing the text "JavaScript is cool!" from the following markup. with it`s class
<h1 class="content">Front end Devs</h1> <div class="content"> <span class="content">JavaScript is cool!</span> </div>
4 Respuestas
+ 4
In case where there are more than one span element of "content" class ...
window.onload = () =>
{
const result = Array
.from( document.querySelectorAll( "span.content" ) )
.filter( el => el.innerHTML == "JavaScript is cool!" );
result.forEach( e => console.log( e ) );
};
If there was only one then you can refer it directly ...
const result = document.querySelector( "span.content" );
+ 2
Looks like you could select the span...
+ 1
Could there be more than one element having "JavaScript is cool!" as their text? or is it the one and only element?
0
I want to select only the element with the text "javaScript is cool!" which is a span by its class which is class="content".