Retrieve the position (X,Y) of an HTML element

The correct approach is to use element.getBoundingClientRect(): var rect = element.getBoundingClientRect(); console.log(rect.top, rect.right, rect.bottom, rect.left); Internet Explorer has supported this since as long as you are likely to care about and it was finally standardized in CSSOM Views. All other browsers adopted it a long time ago. Some browsers also return height and width properties, though … Read more

.prop() vs .attr()

Update 1 November 2012 My original answer applies specifically to jQuery 1.6. My advice remains the same but jQuery 1.6.1 changed things slightly: in the face of the predicted pile of broken websites, the jQuery team reverted attr() to something close to (but not exactly the same as) its old behaviour for Boolean attributes. John … Read more

When I load the page the alert(“hey”) function appears, why does the js function execute despite no onClick call? How do I prevent it from doing so?

Are you sure you get such alert dialog,here i have ran for two times but without such problem,so check your code and clean your browser cache.or you can also change a browser and test it. and if the question is still there, i think there maybe a closure function in your extra import js file.what … Read more

How do I check if an element is hidden in jQuery?

Since the question refers to a single element, this code might be more suitable: // Checks CSS content for display:[none|block], ignores visibility:[true|false] $(element).is(“:visible”); // The same works with hidden $(element).is(“:hidden”); It is the same as twernt’s suggestion, but applied to a single element; and it matches the algorithm recommended in the jQuery FAQ. We use … Read more