i have one single class for margin and i am using this class to two different div but i want to margin 0 in second div, i dont want to change html because if i do that i will have work on many pages so i want to do that either jquery or css. i tried it to do that with child selector but it wont work for me.
<style>
.margn { margin-top:20px;}
</style>
<body>
<div class="margn">hii</div>
<div id="call" class="margn">bye</div>
</body>
for the markup you have given try
$("div:eq(1)").removeClass('margn');
or if you want to remove margn from divs that have class margn
$(".margn:eq(1)").removeClass("margn");
DEMO
you can use jQuery here as per your tag in the question
just right the below code. Remember you include jquery file.
$(document).ready( function() {
$("#call").css("margin-top", "0 !important"); // or
$("#call").css("margin-top", "0");
});
EDIT : Also if you want to use only CSS you can refer the answer by @sandeep below. remember CSS works sepquentially so write your css in proper sequence.
in CSS
.margn{margin-top:20px;} /* after this line write style for your div having id. */
#call {margin:0;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With