user2588892
user2588892

Reputation: 9

hide div's with different values in id name

I have many divs that are name such as:

<div store_id="1"></div>
<div store_id="2"></div>
<div store_id="3"></div>
<div store_id="4"></div>

I am trying to hide them without specifically defining the value by doing this:

    $('div[store_id=' + this.value + ']').hide();

I have a option variable that has the same value as the stor_id div's and also tried:

$('div[store_id=' + option.attr("value") + ']').hide();

but neither of them are found when I check them on chrome source code debugger or working when I plug them in. what am I doing wrong?

option comes from :

var option = $("#idea_store_ids :nth-child("+(parseInt(value)+1)+")");


decentness to #idea_store_ids:

<select id="idea_store_ids" name="idea[store_ids][]" multiple="multiple" style="display: 
none;">

<option value="103">

    4 Wheeling Shirts-To-Go

</option>
<option value="79" selected="selected"> … </option>
<option value="63"> … </option>
<option value="2" selected="selected"> … </option>
<option value="19"> … </option>
<option value="75"> … </option>
<option value="122"> … </option>
<option value="18"> … </option>

entire js:

 $(document).ready(function() {
   $('#idea_store_ids').chosen().change(function(){
    var doai = $(".search-choice-close").map(function(){
      return $(this).attr("data-option-array-index");}
  ).get();
  $.each(doai , function(index, value) { 
    var option = $("#idea_store_ids :nth-child("+(parseInt(value)+1)+")");


  });
   });
});

$("div[store_id=' + value + ']").hide();    

Upvotes: 0

Views: 98

Answers (1)

emdhie
emdhie

Reputation: 379

You can hide <div>s. Try this:

<div store_id="1"></div>
<div store_id="2"></div>
<div store_id="3"></div>
<div store_id="4"></div>
$(document).ready(function() {
    var allDivs = $("div").length;
    for(var x =0; x <  allDivs; x++){
        var element = $("div").attr("store_id",x);
         $(element).hide();
    }                   
});

Upvotes: 1

Related Questions