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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:49:15+00:00 2026-05-23T07:49:15+00:00

I have a little problem, and I can’t figure out where does it come

  • 0

I have a little problem, and I can’t figure out where does it come from.
I’m using jQuery UI (and of course jQuery)

I have the following HTML:

   <input type="checkbox" id="test" value="test"/>
    <label for="test">Show Test</label>
    <div id="checkedDiv"></div>

and the following JS:

function clickChange() {
    var currentText = this.nextSibling.innerHTML;
    this.nextSibling.innerHTML = 
    (this.checked) ? currentText.replace("Show","Hide") :
                     currentText.replace("Hide", "Show");
    $("#checkedDiv").text(this.nextSibling.innerHTML);
}

var test=document.getElementById("test")
test.onclick=clickChange;
$("#test").button();

The problem is that on the first click, the innerHTML doesn’t change. After that it works.
And to be a little more disappointed, the nextSibling seems to change (at least from what is seen in the #checkedDiv), but doesn’t appear on the DOM Tree on firefox/firebug.

Am I missing something ?

Thanks
(if you want to try it yourself, it’s here: http://jsfiddle.net/nvNKW/3/ )

EDIT:

The (or at least one) solution is to use label as suggested by Aziz Shaikh:

function clickChange() {
    var currentText = $(this).button( "option","label");
    $(this).button( "option","label",(this.checked)? currentText.replace("Show","Hide") : currentText.replace("Hide", "Show"));
}

And there is no need to change the html or the button initialisation.

  • 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-23T07:49:15+00:00Added an answer on May 23, 2026 at 7:49 am

    Try setting the label using $("#test").button({ label: newText }); instead of this.nextSibling.innerHTML

    Edit: So your fixed JS function would be:

    function clickChange() {
        var currentText = this.nextSibling.firstChild.innerHTML;
        var newText = (this.checked) ? currentText.replace("Show","Hide") : currentText.replace("Hide", "Show");
        $("#test").button("option", "label", newText);
        $("#checkedDiv").text(this.nextSibling.innerHTML);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem I can't figure out how to solve. I have
I have a little problem that I can't figure out how to solve. I
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have this little problem, that I cannot figure out which arguments to pass
I have a little problem about using jQuery (I really do not know jQuery
I have a little problem using jQuery and sorting a JSON array. What I'm
I have a little problem with autoconf, I know that you can use configure.ac
i have a little problem, i'm searching, but i can't found what i need,
I have a little problem with a query. I'm selecting data using the between
i have little problem in using my application application having msaccess database if 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.