There is a design:

<script> //здесь необходимо задать стиль элементу div к примеру color:#fff </script> <div class="some_div"></div> 

PS You are kindly requested to refrain from answering the type, it is better to change the structure, so no one does. variants of type document.write('<style></style>'); and $(document).ready() also not suitable.

  • 3
    It smells like a crutch ... In css to set the styles in any way? - metazet
  • one
    But what is your catch? When looking at a page, a div looks wrong and you can’t wait to load a house to change its style? - makregistr
  • the style is assigned by condition, the point is that the script calls the function for example change_div(".some_div") as a selector in the parameters, and all divs with the necessary selector acquire certain properties. it is possible to prescribe and load styles, but I would like to find an elegant solution based on the principle of live in jQuery. - FLK
  • one
    You can define some default default style and then update it depending on further manipulations or hide the divas until they update - makregistr
  • four
    The question looks like this - how, without having a variable, work with it. In the general case, the answer is elementary simple - NO, you are still waiting for the download, how is the question 10th. PS: do you want to change the style before loading? css for this is not? -_- - Zowie

4 answers 4

The situation itself is ridiculous. Here is a ridiculous decision for you:

 <script> setTimeout(function() { $('.some_div').css('color', '#fff'); }, 10000); // таймуат - примерное время загрузки нужных элементов </script> <div class="some_div"></div> 

Solutions based on .load will not work, because this event does not "pop up" in any browser.

  • Yes, I agree absurd, this is due to the fact that I want to find alternative solutions to the obvious document.write (), I sincerely hope that it will work out. - FLK

Solution: Any problem is solved by regular methods. Question: What prevents to expose the style after diva initialization? Can competently think through the architecture of the script and have a solution?

    Here is another ridiculous solution:

     <script> setInterval(function() { $('.some_div').css('color','#F00'); }, 1); </script> <div class="some_div">111</div> <div class="some_div">222</div> <div class="some_div">333</div> 
    • Yes, if you still use any flag followed by clearInterval , that’s fine. What a pity that you can not specify as an interval of 0.1 or 0.01! - neoascetic
    • one
      So, why bother? Let him color the divs before he loses his pulse)) - Deonis

    It is not clear how it is to boot, to be honest. Well this will all be executed specifically by the browser. And how you want to do this without jQuery (document) .ready () is also not very clear. If I even remotely understand your question, you can do this:

     <script> //-------- // Здесь блок необходимых настроек и изменений стилей jQuery('.some_class').css('color','red'); // и т.д. //-------- jQuery(document).ready(function(){ // Как ни крути, но ready нужно, что бы отделить момент // полной и неполной загрузки документа // Далее будем привязывать события и т.д., прим: jQuery('.some_class').click(function(){ console.log('Console echo by some_class'); }); }); </script> 
    • without ready is done simply - the script is inserted immediately after downloading all the necessary divs with .some_class, they already exist on the page and the script will find them, the rest of us are not interested. True, this method is crutch and not comfortable. - makregistr