It's quite a simple question, but I'm (trying) to write a JQuery plugin, and I want to use only JQuery. The problem is, I have some styles set for the .active
divs (via JQuery), and on clicking a <div>
it's given a class active
- I know this, because I checked in the developer tools - but it's not given the styles. I tried hardcoding the class onto the <div>
, and it worked fine. I also tried hardcoding the styles in CSS instead of JQuery, and again, it worked. Is there a way of updating the JQuery - onclick of the <div>
- so that the styles are applied when the <div>
is clicked?
$('div.active').css({
'border-style':'solid',
'border-width':'1px',
'border-color':'black',
});
$('div').on('click',function(){
$('div').removeClass('active');
$(this).addClass('active');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="div1">div 1</div>
<div class="div2">div 2</div>
<div class="div3">div 3</div>
<div class="div4">div 4</div>
Also, can you explain why this isn't working for me?
Thanks