This is a beginner's question in JavaScript.crying

Asked 2 years ago, Updated 2 years ago, 29 views

I'm sorry for the basic question

There are several tags with two trs in the tbody. If you press a of the first tr in the tbody here, the second tr appears. The tr of other tbody keeps coming out too... I don't know how to fix it<

$ ('a's classname').click(function()
$(this).parents().find('tr:nth-child(2)').slideToggle();
)};

java

2022-09-21 15:51

2 Answers

What you want is .It should be ear(). Use this method when the object corresponding to the selection criteria must perform the same action separately. Official document

$ ('a's classname').each(function(){
    $(this).click(function(){
        // Tr with clicked a is the first tr and then the tr.I have to slideToggle() so...
        $(this).parents('tr').next().slideToggle();
    });
});

If you do this, instead of doing it together by pressing something, each of you will do a separate move. Try it.


2022-09-21 15:51

The desired tbody is

If you're the first one,

$('tbody:first').find('a's classname').click( /*blar blar*/ );

nth one is

// Caution:
// 0 means 1st, 1 means 2nd matched element
$('tbody:eq(n)').find('a's classname').click( /*blar blar*/ );

// So to get a of the second matched tbody
$('tbody:eq(1)').find('a's classname').click( /*blar blar*/ );


2022-09-21 15:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.