Does a jQuery selector by id always work without quotes and # sign?
Posted
by
anarinsky
on Stack Overflow
See other posts from Stack Overflow
or by anarinsky
Published on 2012-11-18T11:06:44Z
Indexed on
2012/11/18
17:01 UTC
Read the original article
Hit count: 147
jQuery
|jquery-selectors
I suddenly found that while using Mozilla / jQuery v1.8.2 I do not need to use the id with quotes and # sign. For example, $(bt2) works the same as $(“#bt2”), see the code below.
Will this selector always work and are there any potential drawbacks from using this shorter form of selection?
<html>
<head>
<title>append</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready (function(){
$(bt2).click(function(){
$(i1).append("<li>a4</li>", "<li>a5</li>");
});
});
</script>
</head>
<body>
<button id="Button1">Append List</button>
<ul id="i1">
<li>a1</li>
</ul>
</body>
</html>
© Stack Overflow or respective owner