Simple jQuery page not working
…
<script s开发者_开发百科rc="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
<div id ="iAmNew">id="iAmNew"</div>
<script>
$(#iAmNew).style("border", "4px dotted blue");
</script>
…
It doesn't work because you used a non-existant jQuery method, .style()
instead of .css()
. Try:
$('#iAmNew').css("border", "4px dotted blue");
And, basically, 'what Adam said' (in comments):
And he forgot the quotes around the selector (just pointing it out).
If you want to use the native JavaScript style
you should use:
document.getElementById('iAmNew').style.border = '4px dotted blue';
Reference:
css()
.
$("#iAmNew").css("border", "4px dotted blue");
Try this:
<div id ="iAmNew">id="iAmNew"</div>
<script>
$("#iAmNew").css("border", "4px dotted blue");</script>
The style()
method doesn't exist, you're looking for css()
. You also need to put the selector in quotes like so:
$("#iAmNew").css("border", "4px dotted blue");
It should be
$('#iAmNew').css("border", "4px dotted blue");
Use $("#iAmNew").css("border", "4px dotted blue");
精彩评论