QuentinCaffeino
QuentinCaffeino

Reputation: 308

Can't set styles from js

I don't know why but this js script don't work for me:

document.getElementById('logo').style.width="300px";

That what I have included in header:

<link media="screen" href="/styles/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/js/libs.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

That is block I'm trying to set style for:

<a href="/index.php"><div id="logo">Some text</div></a>

Upvotes: 1

Views: 3880

Answers (1)

itamar
itamar

Reputation: 3967

You need to wrap it in something that instantiates it.

window.onload=function(){
document.getElementById('logo').style.width="300px";
};

Or in jQuery:

$(function(){
$('#logo').css( "width", "300" );
});

Upvotes: 3

Related Questions