DEV Community

jccaropino7786
jccaropino7786

Posted on

Keeping empty markers off your HTML using JavaScript

When using .forEach on an array each item on that array will be iterated. If you are iterating empty values (“”) over a ordered or unordered list you will be returned ::markers with nothing attached to them essentially posting an empty string, See example below:

Form submission page

appending element

Too many markers

You have 2 ::markers with content and 2 ::markers with no content. If you were iterating a .forEach over an array and wanted to not have empty markers on your page you can simply look at the data and if the data is equal to an empty string (“”) then .removeChild. Example below.

.removeChild

website view no markers

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
titlexp profile image
Surapat Mekvanich

Nice pictures. It's easier to follow when you screenshot your code.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay