Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How to target pseudo elements

hey all I have pseudo elements from where i am including ico-moon font in my html.

index.html
<div class="response">
   <span class="error" data-icon ='&#xea0f;'>Something went wrong</span>
</div>
style.css
.error::before{
  font-family: 'IcoMoon-Free';
  content: attr(data-icon);
  float: left;
  cursor: pointer;
}

I want to hide response div when user click the ico-moon cross symbol ?

1 Answer

jag
jag
18,266 Points

From what I've read you can't manipulate ::before or ::after. With that being said you will have to just use jQuery or pure javascript to hide error when clicked.

hide.js
$('.error').click(function(){

    $(this).css('color','red')

})
Matthew Francis
Matthew Francis
6,967 Points

Hi, I havent looked into jQuery syntax just yet, mind if you translate this to pure javascript?

jag
jag
18,266 Points
pure.js
var error = document.getElementsByClassName('error')
for(i=0;i<error.length;i++){
    error[i].addEventListener("click", function(){ this.style.visibility = "hidden" });
}