HTML Code
<ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-1714167228247329" data-ad-slot="8611448539" data-adsbygoogle-status="done" data-ad-status="unfilled">
I have checked : https://www.w3schools.com/js/js_htmldom_elements.asp and tried but it not help.
I want to take this element data-ad-status="unfilled"
from HTML using javascript. So, i can use it in if else statement.
Like
if (data-ad-status="unfilled") {
some fuctions;
}
3
Answers
–
document.querySelector("[data-ad-status='unfilled']
this one is electing particular one withdata-ad-status="unfillded"
document.querySelectorAll("[data-ad-status]");
this one is selecting all with thedata-ad-status
attribute.we can use
document.querySelector
to select our element (if there is only one)but in this case we need to use
querySelectorAll
for selecting all the ads elements in html (<ins>
)also now we can loop your logic on every element with that status, using
forEach
this is a example:
async
way I have addedsetTimeOut()
function to wait for around 2 seconds here.2s
is hard coded. change it’s value and try to run it. and I am sure it will solve your problem.asyn-await
function and makeselectAd()
wait till you data get loaded.