I want to set inner html value dynamically from custom label .

<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">

Lightning controller :

 var hideElement = document.getElementById("modal-content-id-1");
 hideElement.innerHTML =  $A.get("{!$Label.c.RefreshMsg}");;

But I am getting error says "[Cannot read property 'innerHTML' of null] Failing descriptor: "

  • 2
    You can't do this because of Locker Service. What are you trying to accomplish? – sfdcfox Mar 25 at 7:40
  • This is body div in my modal container. I want to display 3 different content in my body based on the button click – jessy Mar 25 at 7:47

You can dynamically create aura:html at the button click to display dynamic text(Use settimeout to null the div body after predefined display time), use the below code for reference. Also try to use aura:id in the div element instead of id.

    var div;

    $A.createComponents([["aura:html", {
        "tag": "div",
        "body": 'Pass custom label here to make it text dynamic',
        "HTMLAttributes": {
            "class": "slds-text-align_center"

                        function(component, status, errorMessage) {
                            if (status === "SUCCESS") {
                                try {
                                    div = component[0];

                                } catch (error) {
                                console.log('Error from ' + component.getName() + ' ' + 'Unable to create Error component');

    var div1 = component.find("modal-content-id-1");


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.