Untuk memberikan contoh yang disederhanakan, saya memiliki blok berikut yang diulangi di halaman berkali-kali (ini dibuat secara dinamis):
Saat diklik, saya bisa membuka link induk dengan:
Namun ... Saya harus membahas salah Pada dasarnya, dapatkah seseorang memberi tahu saya cara merujuk pada saudara tingkat yang lebih tinggi tanpa dapat merujuknya secara langsung? Sebut saja kakak. Referensi langsung ke nama kelas kakak laki-laki akan menyebabkan setiap contoh elemen di halaman memudar - yang bukan merupakan efek yang diinginkan. Saya sudah mencoba:
Siapa saja? Terima kasih. To get the closest element by a selector, you use the
The See the following HTML document:
The following code selects the list item with the class category-1 and changes the color of the list item to red:
The following code
selects the closest
The following picture shows the output: The following selects the closest list item element. The closest() method starts with the target element. Since the target element matches with the selector, the closest() method stops searching:
Output:
Was this tutorial helpful ? |