Zsolt Janes
Zsolt Janes

Reputation: 840

How to resize div width with javascript

I would like to resize the pagewrapper div with javascript. I have chrome and would like to use it as userscript. Here is the site link: http://clanbase.ggl.com. I want to take the pagewrapper to 100% width. I have the following code:

// ==UserScript==
// @match http://clanbase.ggl.com/*
// ==/UserScript==

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}

function pagewrapper() {
document.getElementById('pagewrapper').style.Width = "100%";
}

addJQuery(pagewrapper);

Upvotes: 4

Views: 11280

Answers (1)

Jeffrey Sweeney
Jeffrey Sweeney

Reputation: 6124

One thing to note is that non-absolutely positioned divider elements automatically take up 100% of the width, so you might not need to do anything. Just try removing the width property from the pagewrapper element (in the CSS) and see if it works. You could also try overriding the width property:

#pagewrapper {
    width:100%;
}

If setting CSS isn't an option for whatever reason, this script should suffice:

function pagewrapper() {
    document.getElementById('pagewrapper').style.width = "100%";
}

Upvotes: 5

Related Questions