user2090732
user2090732

Reputation:

javascript getting attributes values

How can I get the "width","height" and "background-image" values from the 'style' attribute using javascript ?

<div id="someid" class="someclass" style="width: 100px; height: 100px; background-image: url(https://some image.jpg);">

Upvotes: 0

Views: 75

Answers (2)

Vikrant
Vikrant

Reputation: 5036

JavaScript :
x.style.width;
x.style.height;
x.style.background-image;

Jquery:
$('#x').css('width');
$('#x').css('height');
$('#x').css('background-image');

Upvotes: 1

Bluety
Bluety

Reputation: 1909

You can get properties like so:

// To get width
$('#someid').css('width');
// To get height
$('#someid').css('height');
// To get background-image
$('#someid').css('background-image');

Upvotes: 2

Related Questions