css - Manipulating a <div>'s position through JavaScript -


I & lt; Div & gt; How do I set the top, left, width and height of ? I have already made sure that it floats by inserting the following CSS code:

  div.grid_tooltip {position: absolute; Left: 0 pixels; Top: 0 pixels; }  

To easily obtain the context of the element, you may want to add an ID The attribute for this, such as id = "tooltip" . You can then get a reference and set the style property:

  var e = document.getElementById ('tooltip'); E.style.width = '100px'; E.style.height = '100px';  

If you use a library similar to jQuery, you can get the element without id, and you can set the style like this:

  $ ('div .grid_tooltip'). CSS ({width: '100px', height: '100px'});  

It is still more efficient if the element has an ID, so to find the library it is not to search through all the div elements on the page:

  $ ('# tooltip'). CSS ({width: '100px', height: '100px'});  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -