i need to add id to div.
my code not work.
<div class="quote-box-col14" for="seo">
<label for="seo" class="quote-service-seo">SEO</label>
<input type="checkbox" name="seo" id="seo" value="Y" class="checkbox-seo" />
</div>
js code
$('#quote-box-col14').change(function(){
if($(this).is(":checked")) {
$( "#quote-box-col14" ).attr( "id", "check" );
} else {
$( "#quote-box-col14" ).removeAttr("id");
}
});
js fiddle – http://jsfiddle.net/3syqfnzk/
3
Answers
You are using wrong id. Use on change event of
#seo
instead of#quote-box-col14
.And
$( ".quote-box-col14" )
instead of$( "#quote-box-col14" )
.Use like:
Check Fiddle
First of all there is no
id="quote-box-col14"
.quote-box-col14
is a class.Also you are not listening on the
checkbox
. Simply listen on#seo
.Jquery Code For this should be
This will work fine for you because onChange should use for input type for example
<input type="checkbox" name="seo" id="seo" value="Y" class="checkbox-seo" />
not divAlso class can be access by
.
not#
Working Example is Demo Here
You can view this by inspect Element