jquery loop function; hide div if -


i working on new website (music magazine) , need use handy function; have rough idea how cannot code work.

in review section want display 1 main cd review , other cds mentioned titles in sidebar div. don't want main display cd listed in sidebar @ same time. trying write jquery function hide title sidebar matches main display cds title.

i guess idea create if function here: if (main cd title) == (sidebar cd title) hide (sidebar contains cd title); has loop through elements automatically.

below sample of code affected:

html:

<div class="grid_12 alpha omega upper2" title="vil"> <div class="grid_8 upper alpha omega" id="vil">  

grid_12 main cd , grid_8 sidebar title cd

jquery bit:

if($('.grid_12').attr('title') == $('.grid_8').attr('title')) { $('.grid_8').attr('title').hide(); } 

the jquery code wrong idea how wanna it.

the suggestion putting unique ids array quite good.

thanks in advance.

jacek

you can't hide title, it's meaningless. can hide element, or clear title.

so change either 1 of , "work":

$('.grid_8').hide(); 

or:

$('.grid_8').attr('title', ''); 

reading said again, think understand goal. such code hide element class "grid_8" having title same element class "grid_12":

var titletosearch = $('.grid_12').attr('title'); var matchingdiv = $('.grid_8[title="' + titletosearch + '"]'); matchingdiv.hide(); 

live test case.

this assumes have 1 "grid_12" , several "grid_8" elements. if have more 1 , each "grid_12" contains several "grid_8" , want find 1 of them matching title, here updated code:

var parentgrid12 = $(this).parents(".grid_12"); var titletosearch = parentgrid12.attr("title"); var matchingdiv = parentgrid12.find(".grid_8[title='" + titletosearch + "']"); matchingdiv.hide(); 

the $(this) assumes code being executed event handler of element inside "grid_12". updated fiddle.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -