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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:58:38+00:00 2026-05-16T08:58:38+00:00

I want to edit some HTML I get from a var I saved. like:

  • 0

I want to edit some HTML I get from a var I saved. like:

var testhtml = $('.agenda-rename').html();
console.log($('input',testhtml).attr('name'));

Also tried

console.log($(testhtml).find('input').attr('name'));

But i get undefined? I figured it’d work like an $.ajax, $.get, $.post? How else can i do it?

  • 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-16T08:58:38+00:00Added an answer on May 16, 2026 at 8:58 am

    When you call .html(), you’re only getting the content, not the .agenda-rename. So if the input is a direct child of .agenda-rename, then .find() won’t be able to find it.

    Probably better just to do without the .html() call:

    var testhtml = $('.agenda-rename').clone();  // or .clone(true)
    console.log($('input',testhtml).attr('name'));
    

    Now you have the .agenda-rename element(s) and you’ll be able to search for elements nested inside it/them.


    EDIT: Based on comment, OP doesn’t want to modify the original. As such, .clone() can be used. Answer above has been edited to reflect change.

    If events are attached that should be retained, then you use .clone(true).


    EDIT: The reason $('input',testhtml) and $(testhtml).find('input') give the same result is that they are actually the same thing.

    jQuery converts the first version into the second behind the scenes. As such it is technically a little more efficient to use the second than the first.

    Here’s the code where jQuery makes the switch (after running a bunch of other tests to determine what it was passed).

    http://github.com/jquery/jquery/blob/master/src/core.js#L150

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

Sidebar

Related Questions

No related questions found

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.