Wednesday, 15 January 2014

jquery - How to display nth divs within a certain div using javascript? -



jquery - How to display nth divs within a certain div using javascript? -

i have multiple divs on page , in div there more kid divs floated go across page. want able utilize javascript see width of window , split set width of divs work out how many display.

i have found 2 pieces of code. 1 measures window width , other piece divs , hide rest.

$('div').slice(4).hide(); var width = $(window).width(); $(window).resize(function(){ if($(this).width() != width){ width = $(this).width(); console.log(width); alert(width); } });

my problem how select divs within speciedfied div. have tried hasn't worked. don't know if i'm goin in right direction

$("#maincontent2").append(('div').slice(4).hide());

is javascrpt right way go or css able i'm after?

many thanks

edit: html

<div id='maincontent> <p></p> <div> <div id='maincontent2'> <div><img></img><p></p></div> <div><img></img><p></p></div> <div><img></img><p></p></div> <div><img></img><p></p></div> <div><img></img><p></p></div> </div>

if have got number of div show in particular div can utilize code.

$(#mainconetent2 > div).slice(4).hide());

javascript jquery html

No comments:

Post a Comment