Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

html - Ensuring sequential execution of onClick method in one element(Element has multiple classes, each with one onclick jquery function)

I'm working on a project, and have some problems with jquery.

button(class="my-btn do-btn")

Both my-btn and do-btn have an 'onClick' jQuery each, and I need both the events to occur in sequential manner when the button is clicked.

I cannot modify the format of the element consisting two classes with one onClick function each.

How can I make sure that the my-btn jquery on click function occurs before the do-button jquery function?

Thanks for your help.

question from:https://stackoverflow.com/questions/65915352/ensuring-sequential-execution-of-onclick-method-in-one-elementelement-has-multi

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

1 Answer

0 votes
by (71.8m points)

You don't need to add two classes and two different onClick events. You can invoke only one onClick event and in that function you can add code accordingly as you want to operate things like following:

button(class="my-btn do-btn")

$(my-btn/do-btn).onClick(() => {
  first fn-call;
  second fn-call;
});

//In this way first and second will call sequentially

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...