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

  • SEARCH
  • Home
  • 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 6561197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:33:27+00:00 2026-05-25T13:33:27+00:00

Consider the html <div id=one > <input type=radio value=x name=group > <input type=radio value=y

  • 0

Consider the html

<div id="one" >
<input type="radio" value="x" name="group" >
<input type="radio" value="y" name="group" >
<input type="radio" value="z" name="group" >
</div>

I have two questions regarding the DOM access with Jquery.

  1. Question One

I just want to find the value of input radio which is selected.So i have

Method 1:

var value="";
$("#one input:radio[name=group]").each(function(){
  if($(this).is(:checked)){
   value=$(this).val();
  }
});

Method 2:

var value=$("#one input:radio[name=group]:checked").val();

is there a considerable performance difference in between two methods ? rather than method 2 do that in one line of code..

Or please explain actually what is happening with the line "input:radio[name=group]:checked" inside jquery?

  1. Question Two

I want to set the checked attribute true
to input having value “y”. So

$("input:radio").filter("[value=y]").attr('checked', true);

and

$("#one input:radio[name=group]").filter("[value=y]").attr('checked', true);

will do the same .

Is there any performance difference in adding “div id” and “[name=group]” ?

  • 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-05-25T13:33:27+00:00Added an answer on May 25, 2026 at 1:33 pm

    When it comes down to pure perf, there is one solution I find better: “Do it yourself” (on jsperf )

    I did your test, but it only took me the time to make a copy/paste ;)

    http://jsperf.com/selectoroptimization

    From the result I add, the best method seems to be the second one for the first question but for the second one it depends on the browser.

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

Sidebar

Related Questions

Consider the following code : HTML: <div> <label for='name'>Name:</label> <input type='text' id='name' /> </div>
Consider the following HTML : <div class=list> <select> <option value=one>1</option> <option value=two>2</option> </select> And
Consider the following Html: <div class=one> <span>1. test</span> <span>test</span> </div> <div class=two> <span>2. test</span><span>test</span>
Consider the following HTML: <div class='x'> <ul> <li>Number one</li> <li>Number two</li> <li>Number three</li> <li>Number
Consider the following HTML structure: <div class=content> <div class=field field-type-date field-field-event-date> <div class=field-items> <div
Consider following HTML, I have a div class magic inside main . The magic
Consider the following HTML: <div class=foo id=obj> I should be changed red <div class=bar
Consider the following html code: <div id='x'><div id='y'>Y content</div>X content</div> I'd like to extract
This problem is only in IE. Consider the following HTML: <html> <body> <div style='position:absolute;left:1em;right:1em;top:1em;bottom:1em;overflow:auto;>
Consider the following HTML snippet. The desired effect is to have a dropdown be

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.