I’m working on a small accordion component. I know how to make it work in jQuery using this code:
const eCta = $('.js-accordion-cta');
const eTarget = $('.js-accordion-target');
const state = 'active';
eCta.on('click', function(){
$(this).next(eTarget).toggleClass(state);
$(this).toggleClass(state);
});
I wan’t to avoid using external libraries like jQuery but I can’t get it to work with js. It only works on the first element in the accordion.
const item = document.querySelectorAll(".js-accordion-item");
const eCta = document.querySelector(".js-accordion-cta");
const eTarget = document.querySelector(".js-accordion-target");
const state = "active";
item.forEach(function (item, index) {
eCta.onclick = function () {
this.classList.toggle(state);
this.nextElementSibling.classList.toggle(state);
};
});
<div class="item js-accordion-item">
<a class="cta js-accordion-cta">Accordion Title 1 (cta)</a>
<div class="target js-accordion-target">
<h3>Lorem ipsum item</h3>
<p>Content lorem ipsum dolor sit amet, consectetur adipiscing elit </p>
</div>
</div>
<div class="item js-accordion-item">
...
What is the correct way to loop over dom items to interact with them? Preferable in ES6
http://kamagraday.com kamagra
https://cialisbob.com/ tadalafil
http://medspublic.com over counter viagra walgreens
https://himscanada.com/ price of cialis at cvs
http://levitraoffer.com levitra vs cialis vs viagra reviews
http://prescriptionhim.com/ viagra no prior prescription
http://himshairloss.com/ how to get propecia online
https://viagraxyu.com viagra with a doctor prescription
http://stromectolhumans.com/ ivermectin tablets dosage
https://iwermectin.com/ ivermectin
clomid cost – clomiphene 25mg order clomiphene 100mg
canadian pharmacy viagra online – discount viagra 100mg sildenafil pills in india
https://ivermectineffects.com/ ivermectin for humans for sale
http://ivermectineffects.com ivermectine vidal
https://ivermectinovercounter.com/ ivermectina dosis
tadalafil 2.5 – generic cialis cost cialis canada 40mg
cost for ivermectin 3mg – ivermectin pills oral stromectol cost
slots online – pala casino online slot machine games
vardenafil for sale https://levitrair.com levitra usage
http://ivermectinus.com/ ivermectina
http://zithrozpack.com/ erythrocin
ivermectin for humans https://stromectolus.com where can i buy ivermectin
how much is cialis 10mg – Cialis pharmacy tadalafil medication cost
https://albuterolotc.com/ albuterol 100 mcg
javascript-help.li with safe canadian online pharmacies https://pharmvolk.com online prescriptions no visit
stromectol 3 mg tablets price https://ivermcov.com/# buy ivermectin online for humans
what is aids in cats http://ventolinhfaer.com/ ventolin hfa inhaler 90 mcg albuterol
javascript-help.li vs ivermectin tabletten http://ivermectini.com ivermectin over the counter in the us
javascript-help.li vs generic ivermectin https://ivermectiny.com ivermectin
javascript-help.li recommended ivermectin side effects http://ivermectiny.com ivermectin tablets dosage
javascript-help.li vs ivermectina uso umano prezzo http://ivermectinhum.com ivermectine 1% crГЁme generiek
brand viagra without a doctor prescription http://viagrob.com where can i get viagra
stromectol online canada
furosemide tablets 40 mg for sale lasix medicine price nek nox
lasix 10 mg furosemide 40 mg tablet buy online nek nox
lasix 80 mg buy lasix nek nox
lasix pill lasix 40 mg nek nox
furosemide http://lasixotc.com furosemide 20 mg for loop over elements in vanilla javascript – only the first element in the accordion works – JavaScript Help
ivermectin 50 mg stromectol pill
buy stromectol online uk ivermectin generic cream
ivermectin 5 mg price where to buy stromectol online
bactrim buy https://azithrozpack.com azithromycin 250 mg 6 tablets
ivermectine otc http://ivermectin1.com/ ivermectin dosage chart for humans
https://stromectolo.com – do i need a prescription for ivermectin
clomid goodrx nek nox
Çay veya Kahve istermisiniz Stalkerlar?
http://stromectolus.com – stromectol
https://ivrmectin.com – buy ivermectin
stromectol how much it cost ivermectin for sale
buy vardenafil online paypal – vardenafil pill over the counter ed pills cvs
zyrtec allergy 10 mg – http://allergyd.com
stromectol online canada http://stromectolforte.com/ ivermectin 50 walmart ivermectin for humans
ivermectin https://stromectolforte.com/# ivermectin over the counter in the us ivermectin tablets for humans uk
turmeric viagra http://www.viagwdp.com/ viagra 90 pills prices for viagra
ivermectin where to buy http://www.ivermectinhum.com/ ivermectin for humans dosage
buy viagra online new zealand https://www.viagwdp.com/# order viagra online canadian pharmacy sildenafil online purchase india
ivermectin on line sales ivermectin stromectol merck
viagra price – cialis 20mg for sale tadalafil 10mg us
prednisone 20mg pill – order prednisone 40mg for sale prednisone 5mg for sale
generic xenical 120mg – hydroxychloroquine 400mg sale plaquenil price
tadalafil order online no prescription cialis cost
cost tadalafil generic tadalafil brands
tadalafil price walmart https://cialisicp.com/
https://cialistrxy.com/ where to buy tadalafil on line
tadalafil generic where to buy tadalafil brands
tadalafil cialis https://cialistrxy.com/
tadalafil goodrx https://cialisusdc.com/
where to order tadalafil tablets tadalafil liquid
ivermectin 3mg stromectol otc
order stromectol pill http://ivermectinetc.com/
http://www.ivermectinusd.com/ ivermectin 6 mg