Advertisement
asadsuman

Jquery-Basic

Feb 14th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. <!---Part one--->
  2. 1. jQuery == $
  3. 2. window.jQuery = window.$ = jQuery;
  4. 3.$(document).ready(function(){
  5. })==== $(function(){
  6.  
  7. })
  8.  
  9. 4.যদি সুধু parent element এর মধ্য children element দরকার হয় তবে .children() method ব্যবহার করবে । এই method শুধু parent element এর মধ্যে children element কে select করে ।
  10.  
  11. ৫। আর জদি সব element খুজতে চাই তাহলে .find() method ব্যবহার করতে হবে ।
  12. 6. some example
  13. <!DOCTYPE HTML>
  14. <html lang="en-US">
  15. <head>
  16. <meta charset="UTF-8">
  17. <title>part three</title>
  18. <style type="text/css">
  19. .container{
  20. color:green;
  21. }
  22. .bg{
  23. background:black;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="container">
  29. <h1>Welcom my Website</h1>
  30. <ul class="far">
  31. <h2>lsdkfjdls</h2>
  32. </ul>
  33. <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500</p>
  34.  
  35. <ul class="em container">
  36. <li>Item one</li>
  37. <li>item two</li>
  38. <li>item three</li>
  39. <li>item four</li>
  40. <li>
  41. <ul>
  42. <li>one</li>
  43. <li>two</li>
  44. <li>three</li>
  45. </ul>
  46. </li>
  47. </ul>
  48. </div>
  49. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
  50. <script type="text/javascript">
  51. $(document).ready(function(){
  52. console.log('jquery ready');
  53. //$('ul.em').children('li').css('color','green');//find only child element under parent element.
  54. //$('ul.em').find('li').css('color','red');//find all element under parent element
  55. //$('ul.em').find('li:nth-child(2)').css('color','red');//find first two li element under parent element
  56. //$('ul.em').children('li').first().addClass('gr');//select children first element under the parent element.
  57. //$('ul.em').children('li:nth-child(2)').text('Added with jquery');//select second children element under the parent element.
  58. //$('ul.em').children('li').eq(1).text('Added with jquery');//select second children element under the parent element. eq() method count the element 0,1,2,3.... like this. so first element is 0 and so on.
  59. /*$('ul.em')
  60. .children('li')
  61. .eq(2)
  62. .next()
  63. .text('Added with jquery'); select the 4th item list in the child element. */
  64.  
  65.  
  66.  
  67. //$('li').parent('ul.em').css('background','red');//parent() method select one current set of matched element
  68. //$('li').parents('.container').addClass('bg');//parents() method all select all parent element of selector
  69. $('li').closest('.container').css('background','red');//closest() method select the near/close element of the selector.
  70. console.log($('li').parents('.container'));
  71. console.log($('li').closest('.container'));
  72. });
  73. </script>
  74. </body>
  75. </html>
  76. /*----------------------------------------------------------Event Part one-------------------------------------------------*/
  77. this--- মুলত current যে element select করা হয়েছে সেটা return করে।
  78. <script type="text/javascript">
  79. $(document).ready(function(){
  80. console.log('jquery ready');
  81. $('button').click(function(){এই খানে button select করা হয়েছে।
  82. console.log('Button was clicked');
  83. console.log(this);// bortoman je function select kore hoyesi seita selet kore this method. $() diya wrap korte hoy.
  84. console.log($(this));//use $ and wrap the 'this' on jquery. এই খানে button এর value টা print করা হচ্ছে this use করে।
  85. $(this).text('changed');//
  86. });
  87. });
  88. </script>
  89.  
  90. একই element বার বার select না করে $(this) ব্যবহার করে ভাল।
  91.  
  92. 2.attr() method এই method দ্বারা <a>,<link>tag ও বিভিন্ন tag এর attributes select করা হয় ।
  93. <div class="attr"><a href="asad.com">Asad</a></div>এইখানে a tag এর href এর value asad.com
  94. $('.attr').click(function(){
  95. $('a').attr('href','http://asaduzzamansuman.com');এইখানে তা change হয়ে http://asaduzzamansuman.com করা হয়েছে ।
  96. });
  97.  
  98.  
  99. 3. data() method - শুধু data-ডাটা নাম select করে।
  100. যেমন <button data-file="day">Day</button>
  101. data('file')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement