Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: calculate the top in live jquery
    primarykey
    data
    text
    <p><a href="http://jsfiddle.net/xHE3S/" rel="nofollow noreferrer">http://jsfiddle.net/xHE3S/</a></p> <p>There are 12 li. Each row contains 3 li. So there will be four rows.</p> <p>What I am doing is first calculating the each li location from ul and then using ajax fetching the product data. Ajax data displaying in new row below the clicked li.</p> <p>To display the new li created through ajax i am applying top . now the problem starts here.</p> <p>For first row it displaying correctly just below the row1</p> <p>Now when i click on row 2 product it will calculate the distance again and apply the top to newly created li. While previously created element removed when user clicks on anyother li. So in distance calculation it also calculate the space covered by new created li. So the second row li will display on row3 li because getting wrong <strong>top</strong></p> <p>Here is my code:</p> <pre><code>jQuery(function () { jQuery('.products li a').click(function (e) { e.preventDefault(); jQuery('li.new-rows').remove(); var relativeY = jQuery(this).offset().top - jQuery('ul.products').offset().top; jQuery.ajax({ url: links, beforeSend: function () { alert('Yes'); }, success: function (data) { var dd = jQuery(data).find('#content .product').html(); if (jQuery('.products li.new-rows').length == 0) { jQuery('.products').append('&lt;li class="new-rows"&gt;&lt;/li&gt;'); jQuery('.new-rows').html('&lt;div class="data-len"&gt;' + dd + '&lt;/div&gt;'); jQuery('.new-rows').css({ top: relativeY + 280 }); } else { jQuery('.new-rows').html(dd); jQuery('.new-rows').css({ top: relativeY + 280 }); } } ) };) };) }; </code></pre> <p>in this screen you can see it is getting top correctly</p> <p><img src="https://i.stack.imgur.com/nVNc6.png" alt="properly working . getting right top for created li] ![enter image description here]![enter image description here"></p> <p>while here it is calcultes the height covered by li , which is created using ajax. so top value getting addition of it. you can see it is going on third row.</p> <p><img src="https://i.stack.imgur.com/a58Zd.png" alt="enter image description here"></p>
    singulars
    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.
    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