最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to resize div width with javascript - Stack Overflow

programmeradmin1浏览0评论

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: . I want to take the pagewrapper to 100% width. I have the following code:

// ==UserScript==
// @match /*
// ==/UserScript==

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", ".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);

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.. I want to take the pagewrapper to 100% width. I have the following code:

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

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis./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);
Share Improve this question edited Oct 7, 2012 at 12:45 Hovercraft Full Of Eels 285k25 gold badges266 silver badges388 bronze badges asked Oct 7, 2012 at 12:43 Zsolt JanesZsolt Janes 8402 gold badges9 silver badges26 bronze badges 4
  • 1 Consider changing tags here from java to javascript. They are quite different programming languages. Edit: never mind, I'll do it for you! – Hovercraft Full Of Eels Commented Oct 7, 2012 at 12:44
  • I believe, width needs to start with lowercase w. In addition, if you're already loading jQuery, why not just do $('#pagewrapper').css('width','100%');? – Aleks G Commented Oct 7, 2012 at 12:49
  • Also, you'll want to wrap that in the in the domready or load event, so $(document).ready(pagewrapper); – hobberwickey Commented Oct 7, 2012 at 12:52
  • 1 Sorry but I'm not javascript coder I found some scripts. – Zsolt Janes Commented Oct 7, 2012 at 13:12
Add a ment  | 

1 Answer 1

Reset to default 5

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%";
}
发布评论

评论列表(0)

  1. 暂无评论