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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:30:10+00:00 2026-05-13T19:30:10+00:00

I have one html structure , somethinh like <div> <div id=mydiv> <h3> This is

  • 0

I have one html structure , somethinh like

 <div>

    <div id="mydiv">
        <h3>
        This is a Test Page
        </h3>
        <div>I am inside a div</div>
        <a href="http://www.google.com">Click me</a>  
        <div>Second div</div>     
    </div>
</div>

and one script:

 $(function () {
        var elm = document.getElementById("mydiv").innerHTML;// can use html()of jquery
        alert(elm);
    });

Now elm prints/alerts below code:

  <h3>
        This is a Test Page
        </h3>
        <div>I am inside a div</div>
        <a href="http://www.google.com">Click me</a>  
        <div>Second div</div>  

now my question is what are the ways to get value/access “h3″/”a”

tags from var elm.
Note: I want to use elm.[I know this can easily be done by

 $("#mydiv h3")]

so just want to use var elm….the sln can be both in jQuery/javascript.

  • 1 1 Answer
  • 3 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-13T19:30:11+00:00Added an answer on May 13, 2026 at 7:30 pm

    Trying to search for the h3 or anchor inside your html string isn’t going to work (like the other solutions suggested). You need to change your code so you get the “mydiv” element as a jQuery object and then search inside of it:

    var elm = $('#mydiv');
    alert(elm.html());
    alert(elm.find('h3').text());
    

    Updated

    If you really want to load the html in the string and parse it you can do something like the following:

    $(function () {
        // This is just a plain string of HTML now
        var html = document.getElementById("mydiv").innerHTML;
    
        // Add it to a hidden DOM element
        var hidden = $("<div/>").hide().appendTo("body");
    
        // Add the html, replacing the duplicate ID
        hidden.append(html.replace(/mydiv/, "mydiv2"));
    
        // Get the values
        alert(hidden.find("h3").text());
        alert(hidden.find("a").text());
    
        // Destroy holder
        hidden.remove();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have one html page with frames. The left frame is simply a
I have one page website only using HTML, CSS and JavaScript. I want to
I have the following snippet in one of my html pages : <div class=inputboximage>
This is probably a basic html/css question... I have a simple one-button form that
I've this structure View Html.RenderPartial (1) Html.RenderPartial (2) Then in each one of those
I'd like to structure my website like this: domain.com/person/edit/1 domain.com/person/edit/2 domain.com/person/edit/3 etc. I have
I have some HTML that I need to toggle between two structures - one
I have one site that is displaying html content that needs to be displayed
I have 2 canvases, one uses HTML attributes width and height to size it,
I have an HTML table with one column being email addresses; spambot issues aside,

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.