[CSS] & [JQUERY] [selettore] :lt()

:lt() (selettore CSS e jQuery) (solo jQuery) riguarda gli elementi HTML con un indice minore di quello passato come suo parametro. A differenza del selettore CSS e jQuery :eq(), ma come il selettore CSS e jQuery :gt(), non ha un omonimo metodo.

Sintassi

$(":lt(indice)")

Esempi

<script>
$("#eq").click(function(){
  alert($("li").eq(0).text());
  $("li").eq(1).css("background-color", "yellow");
});
$("#eq2").click(function(){
  alert($("li:eq(0)").text());
  $("li:eq(1)").css("background-color", "yellow");
});
$("#gt").click(function(){
  $("li").gt(1).css("background-color", "yellow");
});
$("#gt2").click(function(){
  $("li:gt(1)").css("background-color", "yellow");
});
$("#lt").click(function(){
  $("li").lt(1).css("background-color", "yellow");
});
$("#lt2").click(function(){
  $("li:lt(1)").css("background-color", "yellow");
});
</script>
<ul id="indice">
 <li>Primo capitolo</li>
 <li>Secondo capitolo
  <ul>
   <li>Sottocapitolo</li>
  </ul>
 </li>
 <li>Terzo capitolo</li>
</ul>
<button id="eq">.eq()</button>
<button id="eq2">:eq()</button><br>
<button id="gt">.gt()</button> <!-- NO -->
<button id="gt2">:gt()</button><br>
<button id="lt">.lt()</button> <!-- NO -->
<button id="lt2">:lt()</button>

Contenuti correlati

  • CSS
  • HTML
  • JavaScript
  • jQuery
  • PHP
  • SQL
  • WORDPRESS

Fonti esterne

jquery, selettori css e jquery

Related Articles

0 Comment

Rispondi