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 9003985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:47:51+00:00 2026-06-16T00:47:51+00:00

Ok so I wanna ask a simple jQuery question about arrays of objects. If

  • 0

Ok so I wanna ask a simple jQuery question about arrays of objects.

If I get all elements (for example all paragraphs) from an html page and store them in an array how can I access one of them to do stuff with it?

For example let’s say I have this html:

<!DOCTYPE html>
<html>
    <head>
        <title></title> 
    </head>
    <body> 
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
    <p>Paragraph 3</p>
    <button id="myButton">Click here</button>

    <script src="jquery-1.6.2.min.js"></script>
    <script src="script.js"></script>
    </body>
</html>

This is my script.js:

$(document).ready(function(){
    $("#myButton").click(function(){

        var $paragraphs = $("p"); 
        $paragraphs.detach();  //Works fine, removes all elements
        //$paragraphs[0].detach();  //Doesn't work!

    }); 
});

I’m trying to call detach on the first element of the array, so that I can remove the first paragraph but it doesn’t seem to work…

Is there any way to access the first paragraph without using id attributes?

  • 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-16T00:47:52+00:00Added an answer on June 16, 2026 at 12:47 am

    Try this

    $($paragraphs[0]).detach();
    

    When you pass a index to the jQuery Object List $paragraphs[0] , the object becomes a
    DOM Object

    var $paragraphs = $("p"); 
    
    var domObj = $paragraphs[0];
    
    var jqueryObj = $(domObj);
    

    So you need to wrap it again as a jQuery Object ..

    Instead you can use the :eq() selector

    var $paragraph = $("p:eq(0)");  // Selects only the first para
                                     // which is a jQuery Object
    $paragraph.detach();   // This works too
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi all i wana ask a question about crystal reporting in vs 2008 lets
I wanna ask you a question about JSON. I want to differentiate product by
i wanna ask you about how to display a 3d model exported from blender/3d
hey guys i wanna ask a question about sending data to database to server
i wanna to ask about the different http,TCP,UDP protocoll in network programing, what is
I wanna ask you best practices about blog front page. I wanna build blog
I just wanna ask what would be better approach to supply these objects in
Guys i just wanna ask if there's a possibility: for example $currenttext = someexamplepls;
I wanna make this rather simple to ask so I can hope for a
Just wanna ask this question. Can I use detailTextLabel in a Custom Cell? I

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.