Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use jQuery to realize the interchange of buttons in two div

Shulou Source: shulou.com Published: 2022-06-01 02:39:15 10月01日 Update

This article mainly explains "how to use jQuery to achieve the switch of buttons in two div". The explanation in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use jQuery to achieve the exchange of buttons in two div".

The effect is as follows

The code is as follows:

$(function () {/ / define a variable equal to all button buttons var btns = $("button"); / / for loop to traverse for (var I = 0; I < btns.length) ) {/ / I controls his subscript to determine the click event of that button btns.onclick = function () {/ / determine if the parent control of this button is div1 if ($(this). Parent (). Is ("# div1")) {/ remove this button $(this). Remove () / transfer to div2 $(this) .appendto ("# div2")} else {/ / otherwise his parent control is div2, then move him to div1 $(this) .appendto ("# div1")}); div {width: 500px; height: 200px; border: 1px; background-color: beige;} button {width: 50px; height: 30px;}

What I chose:

You can also choose:

Mathematics, English, sports, art, physics, chemistry, history, geography, biology, thank you for your reading, the above is the content of "how to use jQuery to achieve the switch of buttons in two div". After the study of this article, I believe you have a deeper understanding of how to use jQuery to achieve the exchange of buttons in the two div. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Buttons two location learning content controls subscript event code sports chemistry history variables geography that is ideas situations effects mathematics articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS MariaDB MySQL Shulou Technology