Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$("#container").css("left") - what is the expected behaviour?

Tags:

jquery

css

$("#container").css("left") should return the left positioning of an element. If the css for the element says left: 20px; the jQuery should return 20px. What should happen for an element that is positioned relative, but not given a CSS left position?

I've noticed that Chrome and Firefox handle this differently. Firefox returns 0px, Chrome returns auto. Here's a JSFiddle to provide a demo of the behaviour. Please view it in Firefox and Chrome.

Is this expected behaviour? To me it looks like Chrome and FF give the element a different default position (0px/auto). Is there a standard that applies in this case, that one of the browsers is violating, and if so, which one is correct?

like image 724
Markie Avatar asked May 22 '14 10:05

Markie


People also ask

What does $( mean in jQuery?

In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery. A (selector) to "query (or find)" HTML elements.

What does $( div p select?

Description. "$("div p")" Selects all elements matched by <div> that contain an element matched by <p>.

What does the jQuery (' P ') line of code do?

<p>This is a paragraph selected by a jQuery method. </p> <p>This is also a paragraph selected by a jQuery method. </p> $("p").

What does $() short and stand for in jQuery?

$ is a short form of jQuery function. $() = jQuery() = window. $() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements.


1 Answers

The default for left is "auto"

like image 107
Happy Avatar answered Nov 16 '22 03:11

Happy