How can I sort div elements based on inner div element content / values using javascript / jQuery? -
i have x amount of divs in page, each div item represents single product , looks this:
<div class="productcontainer"> <li> <img src="my-product-image.jpg"></a> <div class="productinfo"> <h4> <!-- sort divs based on tag content --> <a class="producttitleforsorting" href="product-page-link">name</a><br> </h4> <div class="product-price"> <span id="lowestprice">price: <!-- or sort divs product price span content --> <span class="productpriceforsorting">$xx.xx</span></span> </div> </div> </li> </div>
then have select list / dropdown list i'd sort divs price or alphabetically.
for example, let's have 10 divs (10 products), 1 above on single page. able sort either title (a.producttitleforsorting content), or price (span.productpriceforsorting) on select list change.
any ideas how can go accomplishing javascript / jquery? has done on client side.
i tried using datasort plugin, no luck one, looking new ideas , suggestions. thanks!
i not recommend sorting , reordering dom. if has done on client side store javascript array , sort that. example:
var items = [{price:3,name:"something"}, {price:10,name:"somethingelse"}];
now use javascript sort functions sort , append dom. more efficient moving around dom objects.
Comments
Post a Comment