728x90

html /  trigger

<!DOCTYPE html>
<html lang="en">

<head>
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  <link rel="stylesheet" href="style.css">
</head>

<body>

<h1>완</h1>
<h1>투</h1>
<h1>쓰리</h1>
<h1>포</h1>
<h1>빠입식세븐!</h1>


  <script src="cl.js"></script>
</body>

</html>
$(function(){
  $('h1').click(function(){
    $(this).html(function(idx, html){
      return html + '★';
    })
  })
  setInterval(function(){
    $('h1').last().trigger('click');
  },1000);
})

filter

<!DOCTYPE html>
<html lang="en">

<head>
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
  <link rel="stylesheet" href="style.css">
</head>

<body>

  <h2>유정이</h2>
  <h2>가영이</h2>
  <h2>성민이</h2>
  <h2>포에버</h2>


  <script src="cl.js"></script>
</body>

</html>
$(function(){
  $('h2').filter(':even').css({
    backgroundColor:'black',
    color:'yellow'
  });
});


$(function(){
  $('h2').filter(function(index){
    return index%2==0;}).css({
      backgroundColor:'black',
      color:'yellow'
    });
  });

 

 

$(function(){
  $('h2').css('backgroundColor','green')
  .filter(':even').css('color','yellow');
})
728x90

'Library > Jquery' 카테고리의 다른 글

[Jquery] Upload profile  (0) 2024.04.12
[Jquery] 포인트정리!  (0) 2024.04.11
[Jquery] form 태그 선택자  (0) 2024.04.11
[Jquery] eq, nth-child, nth-of-type / 인덱스선택  (0) 2024.04.11
[Jquery] each로 배열 관리하기  (0) 2024.04.11

+ Recent posts