Guest User

Untitled

a guest
Apr 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. var style = document.createElement('style');
  2. style.type = 'text/css';
  3. style.innerHTML = '.cssClass { color: #F00; }';
  4. document.getElementsByTagName('head')[0].appendChild(style);
  5.  
  6. document.getElementById('someElementId').className = 'cssClass';
  7.  
  8. // style element or locally sourced link element
  9. var sheet = YAHOO.util.StyleSheet(YAHOO.util.Selector.query('style',null,true));
  10.  
  11. sheet = YAHOO.util.StyleSheet(YAHOO.util.Dom.get('local'));
  12.  
  13.  
  14. // OR the id of a style element or locally sourced link element
  15. sheet = YAHOO.util.StyleSheet('local');
  16.  
  17.  
  18. // OR string of css text
  19. var css = ".moduleX .alert { background: #fcc; font-weight: bold; } " +
  20. ".moduleX .warn { background: #eec; } " +
  21. ".hide_messages .moduleX .alert, " +
  22. ".hide_messages .moduleX .warn { display: none; }";
  23.  
  24. sheet = new YAHOO.util.StyleSheet(css);
  25.  
  26. <div id="mydiv"><p>Some content</p></div>
  27.  
  28. <script type="text/javascript">
  29. function change(){
  30. document.getElementById("mydiv").style.backgroundColor = "#ff0000";
  31. }
  32. </script>
  33.  
  34. <script>
  35. $(document).ready(function() {
  36. // add 'style="height:30px;"' to the div with id="foo".
  37. $('#foo').attr("style", {height: "30px"})
  38. });
  39. </script>
  40.  
  41. <script>
  42. $(document).ready(function() {
  43. // add 'style="height:30px;"' to all elements with class="bar".
  44. $('.bar').attr("style", {height: "30px"})
  45. });
  46. </script>
Add Comment
Please, Sign In to add comment