Avatar of ambuli
ambuli
Flag for United States of America asked on

Jquery to update a label

Hi there,
I have the following JS.

        var expandCollapseLabel = document.createElement("label");
        expandCollapseLabel.id = "ExpandCollapseLabelID";
        expandCollapseLabel.innerHTML = "-";

Later on, in another function I have to update the label.
I tried the following.  It is getting called, but the label is not updated.  How can I do this?  Thanks.

 $("#ExpandCollapseLabelID").val("+");
JavaScriptjQuery

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

Like this
expandCollapseLabel.innerHTML = "+";

Open in new window

SOLUTION
Tom Beck

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Julian Hansen

.val() is used for input elements not Label's - you have to treat the label as you would any other text element.
You also seem to be mixing JQuery and straight javascript - to update the element using JQuery as you are attempting you can do this

 $("#ExpandCollapseLabelID").html("+"); 

Open in new window

ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23