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

Top comments (1)

Collapse
 
titlexp profile image
Surapat Mekvanich

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

Create an Account! The only reason people scroll to the bottom...  
is because they want to read more.

Create an account to bookmark, comment, and react to articles that interest you.