javascript - jQuery appendTo() w/ Selectors -


so i've added 4 elements page separate wordpress loop. i'm using jquery appendto() add them within list of posts (loop). works fine except last one... seems not able select using last-child or only-child or nth-child. other 3 elements selected , moved fine using last-child(#).i've tried can think of. think?

of course, once 3 elements moved suppose last 1 left no longer considered last-child or first-child?... only-child doesn't work either...

jquery(document).ready(function ($) {     var toapp1 = $(".recent_updates > .fp_post:nth-child(4)"),         toapp2 = $(".recent_updates > .fp_post:nth-child(7)"),         toapp3 = $(".recent_updates > .fp_post:nth-child(10)"),         toapp4 = $(".recent_updates > .fp_post:nth-child(13)");     var ad1 = $(".recent_updates > #skippingads:nth-last-child(4)"),         ad2 = $(".recent_updates > #skippingads:nth-last-child(3)"),         ad3 = $(".recent_updates > #skippingads:nth-last-child(2)"),         ad4 = $(".recent_updates > #skippingads:last");     ad3.appendto(toapp3);     ad2.appendto(toapp2);     ad1.appendto(toapp1);     ad4.appendto(toapp4); }); 

updated code: (still no working classes rather ids (good point out)

jquery(document).ready(function ($) {     var toapp1 = $(".recent_updates > .fp_post:nth-child(4)"),         toapp2 = $(".recent_updates > .fp_post:nth-child(7)"),         toapp3 = $(".recent_updates > .fp_post:nth-child(10)"),         toapp4 = $(".recent_updates > .fp_post:nth-child(13)");     var ad1 = $(".skippingads:nth-last-child(4)"),         ad2 = $(".skippingads:nth-last-child(3)"),         ad3 = $(".skippingads:nth-last-child(2)"),         ad4 = $(".skippingads:last-child");     ad3.appendto(toapp3);     ad2.appendto(toapp2);     ad1.appendto(toapp1);     ad4.appendto(toapp4); }); 

your seem having duplicate ids in document causes html invalid. when html not valid inconsistent behavior browser browser there's no specification handling invalid html, , therefore no browser bound adhere specification.

i suggest change skippingads ids classes , can use class selectors.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -