TheYorickable
TheYorickable

Reputation: 13

Get style in javascript

I'm trying to resize a div when the size of the div is 50% to 100%. But when I try to console.log the current size of the div it just logs whitespace... Whats wrong?

window.onload = function() {
    //declare vars
    var fullbox = document.getElementById('box'),
        minBut = document.getElementById('down');

    minBut.onclick = function() {
        if(fullbox.style.width == "50%") {
            fullbox.style.width = "100%";
        } else {
            fullbox.style.width = "50%";
        }
    }
}

Upvotes: 0

Views: 291

Answers (1)

Techmonk
Techmonk

Reputation: 1469

that could be the case when the width has not been initialized for that element before. The second time it should be 50%.

tested with adding alert(fullbox.style.width);

FIDDLE

Upvotes: 2

Related Questions