Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

javascript - Jquery - Duplicate a button on the same div container, so I have 2 sets of buttons with the same functionality (above and below the container)

I'm totally new to this, as I'm mainly a designer, so beware: I'm learning. I'm trying to modify a WP plugin, to be able to clone a button via JQuery. The original code is this:

    SliderBehaviour.prototype.setupButtons = function (container, buttons) {
            var _this = this;
            this.$buttons = buttons;
            this.$voteButton = this.$buttons.filter('button[value="vote"]');
            this.$resultsButton = this.$buttons.filter('button[value="results"]');
            this.$previousButton = jQuery("<button type="button" class="totalpoll-button totalpoll-buttons-slider-previous">" + this.poll.config['i18n']['Previous'] + "</button>");
            this.$nextButton = jQuery("<button type="button" class="totalpoll-button totalpoll-buttons-slider-next">" + this.poll.config['i18n']['Next'] + "</button>");                            
            container.prepend(this.$previousButton);
            container.append(this.$nextButton);

After much reading and checking and trying, I added this line: container.append(this.$nextButton).clone(true, true).prependTo(".totalpoll-form"); after the last line of the previous code.

It does duplicate the buttons but they don't work. It actually shows all the buttons (previous, vote, next) instead of only showing "Next" as it does on the original set of buttons below the div.

So basically the buttons show and work below the container, I need a duplicate set of buttons ALSO on top of the container.

Buttons Container Buttons

I'm not sure if a code somewhere else on the plugin is preventing the buttons to work. I understood that using clone (true, true) would duplicate the element and its functionality. I'm confused and sorry if I'm too new to this and I might be asking for help on something totally easy. Thanks in advance!

question from:https://stackoverflow.com/questions/65921589/jquery-duplicate-a-button-on-the-same-div-container-so-i-have-2-sets-of-butto

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...