How to set width of DIV tag using JQuery


Setting width of div tag is very simple but i am not a html/css expert so i did some mistake by setting direct width like this

<div width="100px">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>

and it didn’t work so i google and find out some solution

Solution 1 :

<div style="width:100px">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>

 

Solution 2:

<!DOCTYPE html>
<html>
	<head>
	<title>as3atoz</title>
	<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
	<script>
		$("document").ready(function(){ 
			$("#myDiv").attr('style', 'width:200px;');
		});	
	</script>
	</head>
	<body>
		<div id="myDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium cursus nunc id elementum. Vivamus tincidunt augue vel ipsum congue pulvinar eget nec elit. Aliqua</div>
	</body>
</html>

 

 

One response to “How to set width of DIV tag using JQuery

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s