Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome/Opera jQuery CSS positioning not working
    primarykey
    data
    text
    <p>I have the following code that works fine in IE and in Firefox, but doesn't work correctly in Opera or Chrome. The code basically creates a DIV that is inserted directly after the input. In IE and Firefox, the new div will appear overlapping the input. However in both Opera and Chrome the div will appear next to the lower right corner of the input, the positioning isn't working correctly. Any suggestions?</p> <p>Edit: I've included an image of what I want it to look like, it isn't doing this in Chrome and Opera. The overlap is deliberate. In Chrome/Opera the green div is placed at the lower right corner, this is a starting place, but the position CSS class should modify that.</p> <p><a href="http://aspadvice.com/photos/images_to_go_with_what_ive_learned/images/86290/original.aspx" rel="nofollow noreferrer">Working correctly http://aspadvice.com/photos/images_to_go_with_what_ive_learned/images/86290/original.aspx</a></p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js " type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery.fn.makeDiv = function () { $(this).each(function () { var className = "wFWn"; $(this).after("&lt;div class='" + className + "'&gt;The Div&lt;/div&gt;"); var c = $(this).next("." + className); var topStartPosition = $(this).outerHeight(); var leftStartPosition = $(this).outerWidth(); c.addClass('green'); c.addClass('position'); var pos = $(this).offset(); var iTopOffset = 0; if (c.css("top") != "auto") iTopOffset = parseInt(c.css("top").substring(0, c.css("top").indexOf("px"))); var iLeftOffset = 0; if (c.css("left") != "auto") iLeftOffset = parseInt(c.css("left").substring(0, c.css("left").indexOf("px"))); c.offset({ top: pos.top + topStartPosition + iTopOffset, left: pos.left + leftStartPosition + iLeftOffset }); c.css("position", "relative"); }); return this; }; $(document).ready(function () { $("#txtTest2").makeDiv(); }); &lt;/script&gt; &lt;style type="text/css"&gt; .position {top: -4px; left: -100px; width: 140px; font-size: 11px; } .green { background-color: lime; border: solid 1px black;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="two"&gt; &lt;input name="txtTest2" type="text" maxlength="10" id="txtTest2" /&gt;&lt;br /&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload