As @Valdeirpsr said...
On the line
var home_principal = $$(".cms-index-index")
Remove one of $
, would look like this:
var home_principal = $(".cms-index-index")
In the innerHTML
te 2 problems:
1- In
home_principal[0].innerHTML+="<h1 style="font-size: 32px; margin: 30px auto; text-align: center;">Este site oferece conteúdo impróprio para menos de 18 anos</h1>";
home_principal[0].innerHTML="<div id="master" style="height: 40px; text-align: center;"><span style="padding: 5px; background: green; color: #FFF; font-size: 18px; cursor: pointer;" onclick="maior_idade()">Tenho mais de 18 anos</span><span style="margin-left: 40px; padding: 5px; background: red; color: #FFF; font-size: 18px; cursor: pointer;"onclick="menor_idade()">Tenho menos de 18 anos</span></div>"
In the second line you are about writing the innerHTML
first-line
home_principal[0].innerHTML+="<h1 style="font-size: 32px; margin: 30px auto; text-align: center;">Este site oferece conteúdo impróprio para menos de 18 anos</h1>";
home_principal[0].innerHTML="<div id="master" style="height: 40px; text-align: center;"><span style="padding: 5px; background: green; color: #FFF; font-size: 18px; cursor: pointer;" onclick="maior_idade()">Tenho mais de 18 anos</span><span style="margin-left: 40px; padding: 5px; background: red; color: #FFF; font-size: 18px; cursor: pointer;"onclick="menor_idade()">Tenho menos de 18 anos</span></div>"
2- When you want to use quotes inside other quotes you need to "escape" the internal quotes with \
or change double quotation marks by single quotation marks,
i.e., outside use " and inside ' or vice versa.
With the two mistakes of innerHTML
corrected would look like this:
home_principal[0].innerHTML+="<h1 style='font-size: 32px; margin: 30px auto; text-align: center;'>Este site oferece conteúdo impróprio para menos de 18 anos</h1>";
home_principal[0].innerHTML+="<div id='master' style='height: 40px; text-align: center;'><span style='padding: 5px; background: green; color: #FFF; font-size: 18px; cursor: pointer;' onclick='maior_idade()'>Tenho mais de 18 anos</span><span style='margin-left: 40px; padding: 5px; background: red; color: #FFF; font-size: 18px; cursor: pointer;' onclick='menor_idade()'>Tenho menos de 18 anos</span></div>"
Double quotes to mark the beginning and end of the string and single quotes to mark the beginning and end of attributes of HTML tags
Tip: Add Multiple tags just by adding, it won’t help you and probably other members can ask for the closing of the question.
– Valdeir Psr
About the error, remove a dollar sign
$$
correct would be$
; The secondinnerHTML
is missing the sign of+
, thus it is only rewriting the internal code of the element; it is necessary to "escape" the quotation marks of its code (of bothinnerHTML
), for example"<div id=\"master\" …"
– Valdeir Psr