Skip to main content
Inspiring
Jun 22, 2020 6:32 PM UTC
Question

Anyone knows what is wrong with that Javascript? #Dreamweaver #Javascript #iframe

Changeing CSS of certain element based on certain title of other element with Javascript... to change style works already, but not yet based on title selector...

if (getElemtById(blockrandom).title == ("sophia-lilith-implant")) 

{var style = document.createElement('style');
style.appendChild(document.createTextNode('.contentpane {padding-bottom: 260% !important}'));
document.body.appendChild(style);}

else {alert("hello");}


Thanks in advance

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Legend
Jun 22, 2020 8:49 PM UTC

Not sure what you are trying to do but the code you posted is incorrect. First line should be:

 

if(document.getElementById('blockrandom').title === "sophia-lilith-implant") {

 

See if that makes a difference.

Translate
Inspiring
Jun 22, 2020 7:16 PM UTC
Inspiring
Jun 22, 2020 7:04 PM UTC

Is there maybe a way to do it in pure CSS? I already tried:

.contentpane iframe [title='sophia-lilith-implant'] {
.contentpane {padding-bottom: 260%;}
}

Translate
Legend
Jun 22, 2020 9:04 PM UTC

Try including an 'additional class' in your css stylesheet:

 

.additionalStyles {
padding-bottom: 260%;
}

 

Then use the below javascript to apply the class IF 'blockrandom' title === "sophia-lilith-implant":

 

<script>

const contentpane = document.querySelector('.contentpane');
if(document.getElementById('blockrandom').title === "sophia-lilith-implant") {
contentpane.classList.add('additionalStyles')
}

</script>

 

 

Translate