jQuery/prop()

解説 属性プロパティに値をを取得

.prop(property)

属性プロパティに値を設定

.prop(property, value)

.prop(object)

.prop(function)

sample1
sample1code
$(function(){
  $("#startBtn").click(function(){
  	$(this).prop("disabled",true);
	$("#stopBtn").prop("disabled",false);
  });
  $("#stopBtn").click(function(){
  	$(this).prop("disabled",true);
	$("#startBtn").prop("disabled",false);
  });
});
sample2
sample2code
$(function(){
  $("#s2Check").change(function(){
  	if($(this).prop("checked")){
  	  $("#s2Btn").prop("disabled", false);
  	} else {
  	  $("#s2Btn").prop("disabled", true);
  	}
  });
});
	
sample3
sample3code
$(function(){
  $("#s3Btn").click(function(){
  	if($("#s3Check").prop("checked")){
  	  alert("OK");
  	} else {
  	  alert("No");
  	}
  });
});
	
sample4
sample4code
$(function(){
  $("#allCheck").change(function(){
  	if($(this).prop("checked")){
  	  for(var i=0; i<5; i++){
        document.s4chbox.elements[i].checked = true;
      }
    } else {
      for(var j=0; j<5; j++){
        document.s4chbox.elements[j].checked = false;
      }
    }
  });
});
	
sample5
sample5code
$(function(){
  $("input[name='s5Check']").change(function(){
  	var s5Array = new Array();
  	$("input[name='s5Check']:checked").each(function(){
  	  s5Array.push($(this).val());
  	});
  	console.log(s5Array);
  });
});
	
sample6
s6Div
sample6code
$("div").click(function(){
  var thisId = $(this).prop("id");
  var thisClass = $(this).prop("class");
  var thisName = $(this).prop("name");
  console.log(thisId + "," + thisClass + "," + thisName);
});
	
sample7
sample7code
function s7Func(){
  var s7Obj = new Object();
  s7Obj.title = "sample7";
  s7Obj.id = "s7Id";
  s7Obj.class = "s7Class";
  s7Obj.type = "checkbox";
  s7Obj.value = "sample7";
  s7Obj.checked = true;
  $("#s7Btn").on("click", function(){
    $("#s7Input").prop(s7Obj).after(s7Obj.value);
  });
}
	
sample8
sample8code
$(function(){
  $("input[value='ccc']").prop("checked", true);
});