Do you avoid using document.getElementById(id) and document.all(id) to get a single element, instead use selector $(#id)?
  v2.0 Posted at 11/01/2018 8:16 PM by Fiona Feng

$(#id) is a selector of jQuery. It gets the single element with the given id.

jQuery ​is a fast and concise JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.​

​With jQuery, you can write less code but do more work.

<h1 id="Head1">Hello</h1>
<script type="text/javascript" language="javascript">

Figure - Bad Code​​​

<h1 id="Head1">Hello</h1>
<script type="text/javascript" language="javascript">​​

Figure: Bad Code​

<h1 id="Head1">Hello</h1>
<script type="text/javascript" language="javascript">

Figure: Good Code - Using $("#Head1")​​​

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: