02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

62<br />

CHAPTER 2 ■ COMMON JQUERY ACTIONS AND METHODS<br />

.innerHeight(), .innerWidth(), .outerHeight(), <strong>and</strong> .outerWidth()<br />

The inner height <strong>and</strong> width of an element is the width or height not counting borders or margins. You<br />

can access this information using the .innerHeight() <strong>and</strong> .innerWidth() methods.<br />

If you wish to include the borders in the height or width of the element, use .outerHeight() or<br />

.outerWidth(). To include margins as well, use .outerHeight(true) or .outerWidth(true).<br />

Add a margin <strong>and</strong> border to the paragraph with class foo <strong>and</strong> then log its different widths <strong>and</strong><br />

heights:<br />

var el = $("p.foo");<br />

el.css({<br />

"margin":"20px",<br />

"border":"2px solid black"<br />

});<br />

console.log("Inner width: "+el.innerWidth()+"px");<br />

console.log("Inner height: "+el.innerHeight()+"px");<br />

console.log("Outer width: "+el.outerWidth()+"px");<br />

console.log("Outer height: "+el.outerHeight()+"px");<br />

console.log("Outer width with margins: "+el.outerWidth(true)+"px");<br />

console.log("Outer height with margins: "+el.outerHeight(true)+"px");<br />

This outputs the following in the console:<br />

>>> var el = $("p.foo"); el.c...rgins: "+el.outerHeight(true)+"px");<br />

Inner width: 840px<br />

Inner height: 19px<br />

Outer width: 844px<br />

Outer height: 23px<br />

Outer width with margins: 884px<br />

Outer height with margins: 63px<br />

■ Note Again, your results may vary depending on what operating system you're using.<br />

Affecting Result Sets<br />

To process a set of elements, we need a set of methods that allows us to affect each element in the set.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!