The following is a jquery code that would run when a check box is clicked... But right now I need to assign an id for the input type ,so that this function should work work only for that particular id, what could be the solution?
<!-- HTML PART -->
<li><input id='checkbox' type='checkbox' value='1' checked="checked" /> </li>
<!-- JQUERY PART -->
$("input[type=checkbox]").click(function(){
var count=$("input:checked").length;
if(count==5)
{
$('input[type=checkbox]').not(':checked').attr("disabled",true);
}
else
{
$('input[type=checkbox]').not(':checked').attr("disabled",false);
}
save_skills();
get_skill();
});
If you add id="checkbox"
to the desired checkbox tag and don't use that id anywhere else in the page, then you can use this jQuery to target just that checkbox.
$("#checkbox").click(function(){
// your code
});
If I'm not misunderstood.
$("input[type=checkbox]").click(function(){
if (this.id == 'your-custom-id') {
// your code
}
});
Or
if ('#your-id').click(function(){
// your code
});
Look at following code too, if it is what you want
HTML code
<li><input id='checkbox' type='checkbox' value='1' /> </li>
<li><input id='checkbox1' type='checkbox' value='2' /> </li>
<li><input id='checkbox2' type='checkbox' value='3' /> </li>
<li><input id='checkbox3' type='checkbox' value='4' /> </li>
<li><input id='checkbox4' type='checkbox' value='5' /> </li>
<div id="count"></div>
and the js
$('input[type=checkbox]').each(function() {
$(this).click(function() {
if ($(this).attr("id") == "checkbox2") {
$('#count').html("this is what i want");
}
else {
$(this).attr("disabled", true);
$('#count').html('No this is not');
}
});
});
Here is the Demo http://jsfiddle.net/Simplybj/aZ5wv/7/
Hope this will help you in some way
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.