Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag 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("+");
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Like this
expandCollapseLabel.innerHTML = "+";

Open in new window

SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
.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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial