Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing content of p element using innerHTML

Tags:

javascript

I have the following script:

var before = document.getElementById('before');    
if (switchElement.value == 'single'){
    for (var i=0; i < before.length; i++) {
        if (before[i].id == "before_label") {
            before[i].innerHTML = 'Image';
            break;
        }
    }
    after.style.display = 'none';   
} 

and the HTML looks like:

<div id="before">
    <p id="before_label"> Before Image: </p>
    <input type="file" name="before"  size="40">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000">
</div>

Was wondering why it didn't work and change the inner html to change?

like image 492
adit Avatar asked Oct 29 '25 17:10

adit


1 Answers

To access the innerHTML of before_label, just access it directly:

document.getElementById('before_label').innerHTML = 'Image';
like image 82
Jared Ng Avatar answered Oct 31 '25 08:10

Jared Ng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!