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>

15th Sep 2022, 7:34 AM
Yasin Rahnaward
Yasin Rahnaward - avatar
4 odpowiedzi
+ 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" );
15th Sep 2022, 9:20 AM
Ipang
+ 2
Looks like you could select the span...
15th Sep 2022, 7:49 AM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Could there be more than one element having "JavaScript is cool!" as their text? or is it the one and only element?
15th Sep 2022, 8:11 AM
Ipang
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".
15th Sep 2022, 8:17 AM
Yasin Rahnaward
Yasin Rahnaward - avatar