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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:12:23+00:00 2026-06-12T05:12:23+00:00

HTML <div>my content of the div1 <input/> </div>​ <div>my content of the div2 <input/>

  • 0

HTML

<div>my content of the div1
  <input/>
</div>​

<div>my content of the div2
  <input/>
</div>​

<div>my content of the div3
  <input/>
</div>​

JS

$('input').on('change',function(){
  var x = $('this').parent('div').val();
    alert(x);
})​​​;

My problem is why cannot I get the content of the div which the input was changed ?

  • 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-12T05:12:24+00:00Added an answer on June 12, 2026 at 5:12 am

    Corrected Script

    $('input').on('change',function(){
      var x = $(this).parent('div').html();
      alert(x);
    })​​​;
    
    • val() is for form fields only
    • this should not be quoted.

    Alternative

    If you only want the text of the parent, you can use text(). However, browsers can differ on how they implement it (see the notes here). In this case, it’s probably cleaner to wrap the content you want in another element, like:

    <div>
      <span>my content of the div1</span>
      <input/>
    </div>​
    

    And use script like:

    $('input').on('change',function(){
      var x = $('this').siblings("span").html();
      alert(x);
    })​​​;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following HTML: <body> <div id=div1 onclick=toggleDivs();> div1 content </div> <div id=div2 onclick=toggleDivs();
i'm using div content editable html to get value from input keyboard to post
In jQuery we usually use, for example: var content = $('tr#someid td').find('div').html(); var content
i have my html something like this... <div class = content> <div class =
it works fine for one div (function($) { $(document).ready(function(){ $('#div1').hide(); $('a.plus').click(function(){ $('#div1').slideToggle(); $(this).toggleClass(minus_icon); return
I have a problem with this function: $(#contentdiv).click(function() { $(this).append(<div class='editable'>For some reason this
I have the below xpath expression //div[@class=post-content]//img which runs on a html page, scanning
imagine this html on a page <div id=hpl_content_wrap> <p class=foobar>this is one word and
html() should be used for setting content in non-form elements such as div's. **
I'm loading html content via ajax onto a div (using mootools 1.11 and squeezebox,

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.