I am playing around with selecting elements in the DOM using jQuery, and I tried the following:
$(document).ready(function() {
$("a").toggle(function(){
$("div[@id=SomeID]").hide('slow');
},function(){
$("div[@id=SomeID]").show('fast');
});
});
And in the html source, I do have this section:
<div id="SomeID">
<!-- div code -->
</div>
However, when I click on an anchor tag I get the following error:
Syntax error, unrecognized expression: div[@id=SomeID]
Any ideas as to what is going wrong here? I’m a beginner at jQuery and javaScript, so would appreciate any help.
To select an element by its
idin jQuery, use the same syntax as in CSS:To use the attribute-equals selector format then use:
References: