change the style of a tag within another tag

Asked

Viewed 211 times

0

within a DIV has three A and an IFRAME, I want to change the A style without interfering with IFRAME, but I need to do this in javascript, because I’m developing an api from a single file and I don’t want people to download one. css, as is the case with bootstrap.

PS: I won’t use any api or dependency like Jquery, or others, because the people who are going to download will need one more file.

  • Because you don’t put the style directly in the type tag <a style="colore:red;"> or within the <head> of your document you create a tag <style> and cloca the class a.cor {colore:red;}. I told you to tag <style> no Head just for good practice, but currently not that need anymore, you can put it anywhere in the document...

  • Because the object would have been created completely by javascript, and when you touched it, it would change shape

1 answer

1


The css of a parent page is not propagated to a child iframe, so don’t worry about simply putting:

document.querySelectorAll('div > a').forEach(function(elm){
    elm.style.color = 'white'
});

So we got all the a inside div and iterated with the forEach, going through all the links.

The selector > causes only the first occurrences of the tag a are affected by the style.

  • Thanks, it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.