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
Shaun Moore
6,301 PointsJavascript Remove attr
I'm pretty sure I can do this in Javascript but when a 'button' is clicked I would like it to remove some CSS Ids.
I havent started the Javascript course but I need to do this ASAP :-)
5 Answers
Shezan Kazi
10,807 PointsHi Shaun,
you can do this easily using jQuery. Are you familiar with jQuery or looking for an pure JS solution? For jquery check this out: https://api.jquery.com/remove/
Shezan Kazi
10,807 PointsI am finding it difficult to understand... .content_overlay is not an ID, it is a class. Why are you removing it? I assume you want to remove the ID #view-button?
If so try this and remove the 'onclick="$('.content_overlay').remove();"' part:
onclick = function() {
this.removeAttribute(id);
}
Does this work?
Shaun Moore
6,301 PointsSorry the Content_overlay is an ID so its #content_overlay and when I click #view-button I want the #content_overlay to be removed
Shezan Kazi
10,807 PointsOkay, then try this:
onclick = function() { document.getElementById(content_overlay).removeAttribute(id); }
Shaun Moore
6,301 PointsSo I added this in:
<div onclick = function() { document.getElementById(content_overlay).removeAttribute(id); } id="#view_button" >
View <?php echo $heading_title ?>
</div>
And the button doesn't show up now
#view_button{
background-color: #666;
box-shadow: 2px 2px 6px 0px rgba(102,102,102,0.64);
text-align: center;
font-family: "'QuattrocentoRomanRegular'";
font-size: 25px;
color: white;
padding-top: 20px;
margin:300px auto;
padding-bottom: 20px;
height: auto;
width: auto;
}
Shezan Kazi
10,807 Pointsthat is waht you wanted right?
Shaun Moore
6,301 PointsWhen I click the button I want the #content_overlay removed/gone
Shaun Moore
6,301 PointsSo I am now getting this error:
Uncaught SyntaxError: Unexpected token (
Shaun Moore
6,301 PointsAny answers? on getting this error
Uncaught SyntaxError: Unexpected token (
Shaun Moore
6,301 PointsShaun Moore
6,301 PointsWell I wasen't sure If I could do this with pure CSS
After looking at the link can you do this:
onclick= $varible( ".content_overlay" ).remove();Shezan Kazi
10,807 PointsShezan Kazi
10,807 PointsFor pure JS you could use:
element.removeAttribute(attrName);Shezan Kazi
10,807 PointsShezan Kazi
10,807 PointsCan you post some of your code? That would help speed it up
Shaun Moore
6,301 PointsShaun Moore
6,301 Points