jQuery Simple Method for Getting the Position of DIV and A Tag Elements
- 2021-07-18 06:34:05
- OfStack
This article illustrates how jQuery simply obtains the location of DIV and A tag elements. Share it for your reference, as follows:
1. Get the location of DIV
var top = jquery("#div_id").offset().top; // Get div The upper position of
var left = jquery("#div_id").offset().left; // Get div The left position of
var height = jquery("#div_id").height(); // Get div The height of
var width = jquery("#div_id").width(); // Get div Width of
jquery("#div_id").css({'top':top,'left':left,'height':height,'width':width}); // Settings DIV Adj. css Attribute
2. Get the location of the A tag
<a href="http://localhost/#" rel="external nofollow" onclick="javascript:get_a(this,1)"> Get A Location of the label </a>
<script language="javascript">
function get_a(thisObj,param){
var top = jquery(thisObj).offset().top;
var left = jquery(thisObj).offset().left;
var height = jquery(thisObj).height();
var width = jquery(thisObj).width();
}
</script>
More readers interested in jQuery can check the topics of this site: "Summary of jQuery Page Element Operation Skills", "Summary of jquery Selector Usage", "Summary of jQuery Form Operation", "Summary of jQuery Common Plug-ins and Usage", "Summary of jQuery Form (table) Operation Skills", "Summary of jQuery Extension Skills" and "Summary of jQuery Common Classic Special Effects"
I hope this article is helpful to everyone's jQuery programming.