Skip to content

Instantly share code, notes, and snippets.

@k4200
Created May 20, 2011 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4200/982600 to your computer and use it in GitHub Desktop.
Save k4200/982600 to your computer and use it in GitHub Desktop.
attr and prop in jQuery 1.6.1
<html>
<script src="jquery-1.6.1.js"></script>
<script type="text/javascript">
function test() {
//FF4で確認。他のブラウザも要チェック
console.log($("#div1"));
console.log($("#div1").prop("val")); //NG
console.log($("#div1").attr("val")); //OK
console.log($("#div1")[0].getAttribute("val")); //OK
console.log($("#div2"));
console.log($("#div2").prop("value")); //NG
console.log($("#div2").attr("value")); //NG
console.log($("#div2")[0].getAttribute("value")); //OK
}
</script>
<body>
<div id="div1" val="one">one un aaa</div>
<div id="div2" value="two">two deux bbb</div>
<input type="button" onclick="test();" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment