Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:57:06+00:00 2026-06-17T12:57:06+00:00

<!DOCTYPE HTML> <script src=’http://code.jquery.com/jquery-latest.min.js’></script> <body> <div id=’mydiv’>Hello, buddy.</div> <div id=’mydiv’>Hello, friend.</div> </body> When in

  • 0
<!DOCTYPE HTML>

<script src='http://code.jquery.com/jquery-latest.min.js'></script>

<body>

<div id='mydiv'>Hello, buddy.</div>
<div id='mydiv'>Hello, friend.</div>

</body>

When in JQuery, if I $('#mydiv') it will select only the first div, BUT if I do $('div#mydiv') it will select all of them.

I understand that specifying the element as well as the id, it will prevent from selecting other elements that have the same id but are not divs.

Isn’t this a bug? Shouldn’t $('#mydiv') select all elements which id is ‘mydiv’?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:57:07+00:00Added an answer on June 17, 2026 at 12:57 pm

    Explanation for jQuery

    Also, in your case, jQuery should select only one element, and the first element for ID. Since you have also given div, it uses getElementsByTagName, and matches the attribute with ID. So, it returns all the instances. Please correct me if I am wrong.

    Suggestion

    According to web standards, the id attribute must be unique. So, each element should have unique ID. If you want to use things for multiple elements, you have classes.

    Also, your HTML won’t validate, if you have multiple IDs.

    Also, from the XHTML 1.0 Spec

    In XML, fragment identifiers are of
    type ID, and there can only be a
    single attribute of type ID per
    element. Therefore, in XHTML 1.0 the
    id attribute is defined to be of type
    ID. In order to ensure that XHTML 1.0
    documents are well-structured XML
    documents, XHTML 1.0 documents MUST
    use the id attribute when defining
    fragment identifiers on the elements
    listed above. See the HTML
    Compatibility Guidelines for
    information on ensuring such anchors
    are backward compatible when serving
    XHTML documents as media type
    text/html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<!DOCTYPE HTML> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.2.js></script> <script type=text/javascript> $(#myBtn).on(click,function(){ alert('myBtn Clicked'); }); </script>
<!DOCTYPE html> <html> <head> <meta http-equiv=X-UA-Compatible content=IE=edge /> <script src=resources/js/jquery-1.7.2.min.js> </script> ... ... <script>
The code that I have is as follows: <!DOCTYPE html> <html> <head> <script src=javascript/jquery.js
See example: <!DOCTYPE html> <html> <head> <title>language</title> <script type=text/javascript src=http://www.google.com/jsapi> </script> </head> <body> <div
<!DOCTYPE html> <html lang=en> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js type=text/javascript></script> <script type=text/javascript>
I'm using javascript + PHP <!DOCTYPE html> <html xmlns:fb='http://www.facebook.com/2008/fbml'> <body> <fb:login-button scope='email,user_photos'></fb:login-button> <div id='fb-root'
Consider the following code (includes jQuery): <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
Here is my code: <!DOCTYPE html> <html xmlns:fb=https://www.facebook.com/2008/fbml> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8/> <title>New
I want to edit following code.(This code is come from [http://stackoverflow.com/a/9280414/945688] <!DOCTYPE html> <html>
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> <html> <head> <title>Hijack Example</title> <script type=text/javascript src=./jquery-1.2.1.js></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.