javascript - On click on next button get next element in for each loop building wizard steps -
i need when click on next button select element in second array in foreach loop please pure javascript if there need change each loop loop give me , if there explain solution in pseudo comment.
var stepswrp = document.queryselectorall('.stepwrp'); var creatfrag = document.createdocumentfragment(); stepswrp.foreach(function(element, index, array) { element.classlist.add('notworking'); element.setattribute('data-id', index); actionswrp = document.createelement('div'); actionswrp.classlist.add('actions') var createbtnnext = document.createelement('button'); createbtnnext.innerhtml = 'next'; createbtnnext.classlist.add('nextbtn'); var createbtnpervious = document.createelement('button'); createbtnpervious.innerhtml = 'pervious'; createbtnpervious.classlist.add('pervbtn'); actionswrp.appendchild(createbtnpervious); actionswrp.appendchild(createbtnnext); creatfrag.appendchild(actionswrp); if (index === 0) { actionswrp.removechild(createbtnpervious); element.classlist.remove('notworking'); } if (index === array.length - 1) { var submitbtn = createbtnnext submitbtn.classlist.remove('nextbtn'); submitbtn.classlist.add('submitbtn'); submitbtn.innerhtml = 'submit'; submitbtn.setattribute('type', 'submit'); } element.appendchild(creatfrag); }) stepswrp.foreach(function(item) { item.addeventlistener('click', function(event) { if (event.target.nodename === 'button' && event.target.innertext === 'next' && event.target.classlist.contains('nextbtn') ) { } }) })
.stepsindecator { display: block; width: 100%; margin: 15px 0; } ul.stepsindecator_list { display: table; margin: 0 auto; } li.indecator_no { display: inline-block; margin: 0 10px; line-height: 1; } label.number { display: block; margin: 0; background: #f7f7f7; max-width: initial; padding: 1.5rem 2rem; border-radius: 50%; border: 2px solid #ccc; color: #2897a9; } .stepwrp { display: block; width: 100%; height: 200px; background: #ccc; position: relative; } .actions { position: absolute; bottom: 0; padding: 10px; right: 0; left: 0; display: block; background: #1a95ff; text-align: center; } .actions .next, .actions .prev { display: inline-block; margin: 0 10px; min-width: 74px; border: 0; padding: 3px 25px; border-radius: 3px; } .actions .next {} .actions .prev {} .notworking { display: block; position: relative; } .notworking:after { content: ''; position: absolute; top: 0; right: 0; left: 0; bottom: 0; width: 100%; height: 100%; z-index: 5; background: rgba(0, 0, 0, 0.57) }
<div class="container"> <div class="row"> <div class="stepsindecator"> <ul class="stepsindecator_list"> <li class="indecator_no"><label class="number">1</label></li> <li class="indecator_no"><label class="number">2</label></li> <li class="indecator_no"><label class="number">3</label></li> <li class="indecator_no"><label class="number">4</label></li> </ul> </div> <div class="clearfix"></div> <div class="col-lg-4 step"> <div class="stepwrp "> text content 1 </div> </div> <div class="col-lg-4 step"> <div class="stepwrp"> text content 2 </div> </div> <div class="col-lg-4 step"> <div class="stepwrp frist"> text content 3 </div> </div> </div> </div>
Comments
Post a Comment