SomeoneS
SomeoneS

Reputation: 1279

Resize first image in div

I need to set specific width and height of image (in css), with jquery, but only for first image in one div. Is it posibble?

Upvotes: 2

Views: 1336

Answers (3)

thecodeparadox
thecodeparadox

Reputation: 87073

#your_div is refers to div that contains image, may be you've something else.

$('#your_div img:first').css({
   height: 200, // also use '200px' or something other
   width: 200  // '200px' or something other
});

alternative of img:first is img:eq(0).

Read about jQuery :first and :eq()

Upvotes: 8

xavden
xavden

Reputation: 76

try with it:

$('#yourDiv img:first-child').css({width:'100px',height:'100px'});

Upvotes: 2

Chuck Norris
Chuck Norris

Reputation: 15200

$("#myDiv img:first").width(100).height(100);

Here is JsFiddle example.

Upvotes: 4

Related Questions