Avant Garde Black Font With White Border

Active3 years, 5 months ago

× Please fill Font Style, Font Size, Thread Color and Text Line 1 for all the selected locations Customize this product 1 SIZE & COLOR. 3 EMBROIDERY LOCATIONS. Customize one or more locations. Additional Text to Greek Letters. Over Kappa View Colors.

I am new in JavaScript and still learning various things. Right now i'm stuck with adding and removing li elements from the list. I did the exercise just fine using jQuery, but now have difficulties with the pure JS version of the same task.

The main idea is to add a new li element by clicking on the button, and remove the the element by clicking on the X button right next to it. I have tried using 'this' and other advices mentioned in similar questions here on Stackoverflow, but nothing worked for me. Could you, please, guide me what am I doing wrong?

P.S. the adding function seems to be working in snippet, but console logs error: cannot read property 'addeventlistener' of null.

AniAni

3 Answers

This returns a non-live collection:

Which means that it will only contain the objects which exist at the point of the method call. You need to call getElementsByClassName() after the creation of the new li elements, and attach the EventListeners on the invidual buttons. Just remember not to put an EventListener twice on the buttons.

A nicer solution

Better yet: do not use getElementsByClassName(), just attach the event handler directly in the function, in which you create the new button. That way, you don't have to worry about pre-existing event handlers:

meskobalazsmeskobalazs
12.6k1 gold badge24 silver badges48 bronze badges

In your case, btn is a node list of elements, not an element, so you can't attach an event to an array. You need to iterate through them:

Marcos Pérez GudeMarcos Pérez Gude
18k3 gold badges29 silver badges54 bronze badges

I am learning too and this was a good little challenge as a newcomer. Thanks to rlemon for pointing us in the right direction with that article link. I learnt something here.

In case you were interested what I arrived at:https://jsfiddle.net/nyxhj0tg/1/

JS:

DoidgeyDoidgey
2,6939 gold badges38 silver badges74 bronze badges

Not the answer you're looking for? Browse other questions tagged javascriptappendchildremovechild or ask your own question.

ITC Avant Garde Gothic Book
ITC Avant Garde Gothic Demi
ITC Avant Garde Gothic Book Oblique
ITC Avant Garde Gothic Demi Oblique
Lubalin Package 4 (ITC Avant Garde Part 1-6)
Avant garde black font
Lubalin Package 5 (ITC Avant Garde Part 2-4)
ITC Avant Garde Gothic Cyrillic Asian
ITCAvant Garde Std-Bk Cn
ITCAvant Garde Std-Md
ITCAvant Garde Std-Md Cn
ITC Avant Garde Gothic® Bold
ITC Avant Garde Gothic® Book
ITC Avant Garde Gothic® Medium
ITC Avant Garde Gothic 1 Volume
ITC Avant Garde Gothic 2 Volume
ITC Avant Garde Gothic® Bold Oblique
ITC Avant Garde Gothic® Book Oblique
ITC Avant Garde Gothic® Demi Bold
ITC Avant Garde Gothic® Extra Light
ITC Avant Garde Gothic® Medium Oblique
ITC Avant Garde Gothic® Bold
ITC Avant Garde Gothic® Book
ITC Avant Garde Gothic® Book
ITC Avant Garde Gothic® Demi
ITC Avant Garde Gothic® Medium
ITC Avant Garde Gothic® CE Book
ITC Avant Garde Gothic® CE Demi
ITC Avant Garde Gothic® CE Book
ITC Avant Garde Gothic® ExtraLight
ITC Avant Garde Gothic® CE Book Oblique
ITC Avant Garde Gothic® ExtraLight Oblique
ITC Avant Garde Gothic® Multilingual Book
ITC Avant Garde Gothic Selection
ITC Avant Garde Gothic® Multilingual Medium
ITC Avant Garde Gothic CE Complete Family Pack
ITC Avant Garde Gothic® Medium Condensed Oblique
ITC Avant Garde Gothic CE Volume
ITC Avant Garde Gothic Multilingual Complete Family Pack
ITC Avant Garde Gothic Condensed Volume
ITC Avant Garde Gothic® Cyrillic Medium Regular
ITC Avant Garde Gothic® Multilingual Bold Oblique
ITC Avant Garde Gothic® Multilingual Bold Regular
ITC Avant Garde Gothic® Multilingual Medium Oblique
ITC Avant Garde Gothic Turkish Volume
ITC Avant Garde Gothic Western Volume
ITC Avant Garde Gothic® Condensed Bold
ITC Avant Garde Gothic® Condensed Book
ITC Avant Garde Gothic® Condensed Demi
ITC Avant Garde Gothic® Cyrillic Book
ITC Avant Garde Gothic® Extra Light Oblique
ITC Avant Garde Gothic Multilingual Volume
ITC Avant Garde Gothic® CE Book Oblique
ITC Avant Garde Gothic® CE Demi Oblique
ITC Avant Garde Gothic® Condensed Medium
ITCAvant Garde Std-Bk Cn Obl
ITCAvant Garde Std-Bold
ITCAvant Garde Std-Bold Cn
ITCAvant Garde Std-Demi Cn
ITCAvant Garde Std-Md Cn Obl
ITCAvant Garde Std-Md Obl
ITCAvant Garde Std-XLt
ITCAvant Garde Std-XLt Cn
ITC Avant Garde Gothic Cyrillic Volume One
ITC Avant Garde Gothic® Bold Oblique
ITC Avant Garde Gothic® Book Oblique
ITC Avant Garde Gothic® Demi Bold
ITC Avant Garde Gothic® Demi Oblique
ITC Avant Garde Gothic® Baltic Book
ITC Avant Garde Gothic® Book Oblique
ITC Avant Garde Gothic® CE Demi Bold
ITC Avant Garde Gothic® Medium Oblique
ITC Avant Garde Gothic® Turkish Book
ITC Avant Garde Gothic Baltic
ITC Avant Garde Gothic® Bold Condensed Oblique
ITC Avant Garde Gothic® Book Condensed Oblique
ITC Avant Garde Gothic® Demi Condensed Oblique
ITC Avant Garde Gothic® Extra Light Condensed
ITC Avant Garde Gothic® Baltic Book Oblique
ITC Avant Garde Gothic® Baltic Demi Bold
ITC Avant Garde Gothic® Demi Bold Oblique

Avant Garde Black Font With White Border Collie

ITC Avant Garde Gothic® Turkish Demi Bold
ITC Avant Garde Gothic Cyrillic Accented
ITC Avant Garde Gothic Cyrillic Volume
ITC Avant Garde Gothic® CE Demi Bold Oblique
ITC Avant Garde Gothic® Cyrillic Bold Regular
ITC Avant Garde Gothic® Multilingual Book Oblique
ITC Avant Garde Gothic® Multilingual Demi Bold
ITC Avant Garde Gothic® Turkish Book Oblique
ITC Avant Garde Gothic® Extra Light Condensed Oblique

Avant Garde Black Font With White Border Designs

ITC Avant Garde Gothic® Cyrillic Extra Light Regular
ITC Avant Garde Gothic Cyrillic Complete Family Pack
ITC Avant Garde Gothic® Cyrillic Bold Oblique Regular
ITC Avant Garde Gothic® Cyrillic Medium Oblique Regular
ITC Avant Garde Gothic® Multilingual Extra Light Regular
ITC Avant Garde Gothic® Basic Family Pack
ITC Avant Garde Gothic® Cyrillic Demi Bold
ITC Avant Garde Gothic® (EF) Bold Alternates

Avant Garde Font Style

ITC Avant Garde Gothic® (EF) Book Alternates
ITC Avant Garde Gothic® Condensed Bold Oblique

Free Avant Garde Font Truetype

ITC Avant Garde Gothic® Condensed Book Oblique