I would like to stir this up using the javascript function. Can I refer to more than one item?

  • 2
    jQuery: $ (". className"). css ('display', 'none'); // or $ (". className"). hide (); each, as I understand it for clarity? to the prefix increment: var a = [1,2,3]; for (var i = 0; i <a.length;) {console.log (a [++ i])} for (var i = 0; i <a.length;) {console.log (a [i ++] )} here the difference will be noticeable. @AlexWindHope, and your code is all right. If you are even more as thorough as possible, the for loop itself is redundant, since easily replaced by while - Specter
  • I'm not just talking about js, I'm talking about programming languages ​​as a whole, because for all of it, a more convenient "wrapper" over a while , i.e. a while more general concept than a for loop, although it can be concluded with such success that goto , i.e. its assembly sources are a panacea -------------- and it seems to me that this is oftop - Specter
  • Hmm, it seemed to me :-) - karmadro4
  • @ustal my answer is what you want? - Rules

2 answers 2

Fetching elements by class and inserting them inline style - in Hindu.

 var stylesheet = document.styleSheets[0]; stylesheet.insertRule( 'div.undisplayed { display: none; }', stylesheet.cssRules.length ); 
  • Since I screwed up with the increment, I propose a kosher solution as a penance. - karmadro4
  • one
    @Rules, corrected, thank you. Although I do not think that the stylistic and grammatical error pulls did not screw up , we are not on the forum of philologists. By the way, the regular season failed. Read here . - karmadro4
  • If there was even one more condition, it would not be like that already (width <200 etc). But the problem has been solved and, by the way, this is the first time I see it (a shame on my gray hair), therefore a plus) - Sh4dow
  • @ alex_90> Yes @ karmadro4 schmuck, even he cannot admit his mistakes .. Why did you draw here? You do not understand this topic and did not understand a word of what was written. Let's take a specific criticism, and ask to crow in another place. - karmadro4
 <html> <head> <title>brg</title> </head> <body> <div class="divobj someclass" style="left: 0px;">A</div> <div class="divobj otherclass" style="left: 30px;">B</div> <div style="left: 60px;">C</div> <div class="divobj" style="left: 90px;">D</div> <style> .divobj{ position: absolute; background-color: #FF0000; width: 30px; height: 30px; top: 0px; } </style> <script> window.onload=function(){ function getElementsByClassName(where, className){ //Функция работает во всех //браузерах а document.getElementsByClassName везде кроме IE<9 var allElements = where.getElementsByTagName("*"); //Получаем все тэги var elements = []; for(var i=0;i<allElements.length;i++){ if(new RegExp(""+className,"g").test(allElements[i].className)){ // Отсеиваем //по className elements.push(allElements[i]); } } return elements; // Возвращяем результат } objs=getElementsByClassName(document,"divobj"); // Получаем все обьекты с классом some for(var i=0;i<objs.length;i++){ obj=objs[i]; if(obj.tagName=="DIV"){ // Если дейстаительно это div то obj.style.display = "none"; // Присваеваем обьекту свойство } } } </script> </body> </html> 

PS: the best alternative is proposed @ Kotik 'om: ": Functions for searching elements by classes and tags

PPS will leave your answer if anyone is interested and DO NOT MINUS! MY CODE WORKS PERFECTLY!

PPPS updated code specifically for @ karmadro4

  • 2
    //Функция неправильно работает во всех браузерах... It should be like this ;-) - karmadro4
  • five
    @Rules Even if it works, it's still a comment @ karmadro4 is funny :)! [] [1] [1]: i1195.photobucket.com/albums/aa394/TSGIGOR/FUNNY/7.gif - Costantino Rupert
  • one
    @Rules Because the conceptually correct answer has already given @ karmadro4, and following the principle of [ DRY ] [1] is usually not a bad idea :) [1]: en.wikipedia.org/wiki/Don't_repeat_yourself - Costantino Rupert
  • four
    @Rules, why are you shouting something ...> MY CODE PERFECTLY WORKS! It is not true, it only speaks about the wrong testing. Bet? - karmadro4
  • four
    What are the rates? I have 1008 points and am not afraid to lose. - karmadro4