الفرق بين المراجعتين ل"jQuery/first child selector"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE:المحدد <code>‎:first-child()‎‎‎‎</code>‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎ في jQuery}}</noinclude>
 
<noinclude>{{DISPLAYTITLE:المحدد <code>‎:first-child()‎‎‎‎</code>‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎ في jQuery}}</noinclude>
  
== المحدد ‎:first-child ==
+
== المحدد <code>‎:first-child</code> ==
  
 
=== الوصف ===
 
=== الوصف ===
يحدد كل العناصر التي تكون أول ابن من أصلها.
+
يحدد كل العناصر التي تكون أول ابن للعنصر الأب الذي تتبع له.
  
 
=== <code>jQuery( ":first-child" )‎</code> ===
 
=== <code>jQuery( ":first-child" )‎</code> ===
 
أُضيف مع الإصدار: [http://api.jquery.com/category/version/1.1.4 1.1.4].
 
أُضيف مع الإصدار: [http://api.jquery.com/category/version/1.1.4 1.1.4].
  
في حين أن <code>‎[[jQuery/first selector|:first]]</code> لا يتطابق إلا مع عنصر واحد فقط، يمكن أن يتطابق المُحدد ‎<code>:first-child</code> مع أكثر من عنصر بواقع عنصر واحد لكل أب.وهو يعادل ‎<code>[[jQuery/nth child selector|:nth-child(1)]]</code>‎.
+
في حين أن <code>‎[[jQuery/first selector|:first]]</code> لا يتطابق إلا مع عنصر واحد فقط، يمكن أن يتطابق المُحدد ‎<code>:first-child</code> مع أكثر من عنصر بواقع عنصر واحد لكل أب. وهو يعادل ‎<code>[[jQuery/nth child selector|:nth-child(1)]]</code>‎.
  
 
=== أمثلة ===
 
=== أمثلة ===
العثور على أول <code>[[HTML/span|<nowiki><span></nowiki>]]</code> في كل <code>[[HTML/div|<nowiki><div></nowiki>]]</code> مطابقة لوضع خط تحت النص وإضافة حالة حومان.<syntaxhighlight lang="html">
+
العثور على أول <code>[[HTML/span|<nowiki><span></nowiki>]]</code> في كل <code>[[HTML/div|<nowiki><div></nowiki>]]</code> مطابقة لوضع خط تحت النص وإضافة تنسيق عند مرور مؤشر الفأرة فوق العنصر:<syntaxhighlight lang="html">
 
<!doctype html>
 
<!doctype html>
 
<html lang="en">
 
<html lang="en">
سطر 57: سطر 57:
  
 
== مصادر ==
 
== مصادر ==
* [http://api.jquery.com/first-child-selector/ صفحة المحدد ‎‎:file()‎‎‎‎ في توثيق jQuery الرسمي].
+
* [http://api.jquery.com/first-child-selector/ صفحة المحدد ‎‎:first-child-selector في توثيق jQuery الرسمي].
 
[[تصنيف:jQuery]]
 
[[تصنيف:jQuery]]
 
[[تصنيف:jQuery Method]]
 
[[تصنيف:jQuery Method]]
 
[[تصنيف:jQuery Selectors]]
 
[[تصنيف:jQuery Selectors]]

مراجعة 09:32، 17 مايو 2018


المحدد ‎:first-child

الوصف

يحدد كل العناصر التي تكون أول ابن للعنصر الأب الذي تتبع له.

jQuery( ":first-child" )‎

أُضيف مع الإصدار: 1.1.4.

في حين أن ‎:first لا يتطابق إلا مع عنصر واحد فقط، يمكن أن يتطابق المُحدد ‎:first-child مع أكثر من عنصر بواقع عنصر واحد لكل أب. وهو يعادل ‎:nth-child(1)‎.

أمثلة

العثور على أول <span> في كل <div> مطابقة لوضع خط تحت النص وإضافة تنسيق عند مرور مؤشر الفأرة فوق العنصر:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>first-child demo</title>
  <style>
  span {
    color: #008;
  }
  span.sogreen {
    color: green;
    font-weight: bolder;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<div>
  <span>John,</span>
  <span>Karl,</span>
  <span>Brandon</span>
</div>
<div>
  <span>Glen,</span>
  <span>Tane,</span>
  <span>Ralph</span>
</div>
 
<script>
$( "div span:first-child" )
  .css( "text-decoration", "underline" )
  .hover(function() {
    $( this ).addClass( "sogreen" );
  }, function() {
    $( this ).removeClass( "sogreen" );
  });
</script>
 
</body>
</html>

مصادر