Advertisement
asadsuman

Jquery-EventPart1

Feb 15th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="en-US">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Event part 1</title>
  6. <link rel="stylesheet" href="day.css" />
  7. </head>
  8. <body>
  9. <h1>My Website</h1>
  10. <ul>
  11. <li>one</li>
  12. <li class="test">2</li>
  13. <li>3</li>
  14. <li>4</li>
  15. <li>5</li>
  16. </ul>
  17. <button data-file="day">Day</button>
  18. <button data-file="night">Night</button>
  19. <div class="attr"><a href="asad.com">Asad</a></div>
  20. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
  21. <script type="text/javascript">
  22. $(document).ready(function(){
  23. console.log('jquery ready');
  24. var link = $('link');//wap the selector better way
  25. $('button').click(function(){
  26. //console.log('Button was clicked');
  27. //console.log(this);// bortoman je function select kore hoyesi seita selet kore this method. $() diya wrap korte hoy.
  28. //console.log($(this));//use $ and wrap the 'this' on jquery.
  29. //$(this).text('changed');//
  30.  
  31.  
  32. //process 1
  33. //$('link').attr('href','night.css');Hard code bad code process 1
  34.  
  35. //process 2
  36. /*
  37. var stylesheet = $(this).text().toLowerCase();//return function what we need to select
  38. console.log(stylesheet);//print the value or stylesheet
  39. $('link').attr('href',stylesheet + '.css');//return stylesheet value.css*/
  40.  
  41.  
  42. /*process 3 using HTML5 Data attributes
  43. var stylesheet = $(this).attr('data-file');
  44. console.log(stylesheet);
  45. $('link').attr('href',stylesheet + '.css');*/
  46.  
  47. /*process 3 using jquery data() method
  48. var stylesheet = $(this).data('file');//data() method select the value which is associated in data attributes
  49. console.log(stylesheet);
  50. $('link').attr('href',stylesheet + '.css');*/
  51.  
  52.  
  53. /*Better way to wrap the selector and use it */
  54. var $this = $(this),
  55. stylesheet = $this.data('file');//data() method select the value which is associated in data attributes
  56. link.attr('href',stylesheet + '.css');
  57. $this
  58. .siblings('button')//select same buttons
  59. .removeAttr('disabled')// jodi button er attributes er modde konota disabled thakle seta remove koto
  60. .end()//uporer process ses koro
  61. .attr('disabled','disabled');//eta abar this object dara disabled kaj korbe.
  62.  
  63.  
  64. });
  65. /*$('.attr').click(function(){
  66. $('a').attr('href','http://asaduzzamansuman.com');
  67. });*/
  68. //$('li.test').siblings().css('color','red');select all except test classs
  69. });
  70. </script>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement