0

I've searched all over the internet for this answer and I'm still clueless, maybe one of you will know. Basically I'm wondering if in a .css file could you theoredically change the css of an object based off of its text

for example:

h1[innerText="some text thats in the h1"] {
   /*styles oh what wonderful styles*/
}
SoulDaMeep
  • 57
  • 6

1 Answers1

1

yeah you can use JavaScript with if and else statement as if condition satisfies. it will be executed to change inner HTML. Give me 2 mins to attach code. I can only do this by using js. Further properties can be introduce as here first the color was nothing but after that I introduced pink color as background.

x = document.getElementById('text')
y = x.innerHTML


if (y=="her") {
 x.innerHTML = "Paragraph changed!";
  document.getElementById("p2").style.backgroundColor = "pink";
}else{
  console.log('lol')
}
#p2{
width:200px;
height:100px;
padding-left: 10px;
}
<div class="p2" id="p2">
<h1 id='text'>her</h1>
</div>
ash
  • 1,065
  • 1
  • 5
  • 20
  • But he asked if you can do it purely in CSS, which you can't. – Pavel Schiller Feb 18 '22 at 07:04
  • still cool to know ig, but if you cant do it purely in css than noted ig – SoulDaMeep Feb 18 '22 at 07:06
  • @SoulDaMeep But I think that these are the functionalities and they are associated with JavaScript. See them like building construction. HTML = walls and structure , CSS = wallpapers and orientation and JS = electricity and Regular Movements – ash Feb 18 '22 at 07:15
  • @ash i know that but i was just wondering if i could change the wallpaper based off the name on the door if you know what im saying – SoulDaMeep Feb 18 '22 at 07:18
  • @SoulDaMeep trying to find a way wait please – ash Feb 18 '22 at 07:20