Reputation: 349
Im trying to toggle a class to html tag when someone click on button. My button has a ID vertical-grid (#vertical-grid) and when i click on button nothing happens?
<script>
$("#vertical-grid").click(function(e){
$("html").toggleClass("vertical-rhythm-grid");
e.preventDefault();
});
</script>
This is html of a button
<a id="vertical-grid" class="btn bggreen" href="#" role="button">DOWNLOAD</a>
I don't know if it matters but my HTML tag already has a no-js class
<html class="no-js" lang="">
Upvotes: 2
Views: 70
Reputation: 1358
Try the addClass
function:
<script>
$("#vertical-grid").click(function(e){
$("html").addClass("vertical-rhythm-grid");
e.preventDefault();
});
</script>
This should work.
Upvotes: 0
Reputation: 1590
There might be many reasons for it why it is not working.
Like:
- You may have used same id twice or more in that page.
- Jquery Conflict.
- Jquery Library not loaded properly.
To solve these types of problem always try to look once in firebug console. It helps to solve problem very easily.
If you can see your error in your console just comment it here I will try to help you.
Upvotes: 1
Reputation: 302
Try this
<script>
$(document).on('click', '#vertical-grid', function(e){
$("html").toggleClass("vertical-rhythm-grid");
e.preventDefault();
});
</script>
Upvotes: 0