Click here to Skip to main content
15,892,199 members
Articles / Programming Languages / Javascript

Extend HTML Elements in JS with a 'Factory'

Rate me:
Please Sign up or sign in to vote.
1.80/5 (3 votes)
27 Mar 2023CPOL3 min read 4.7K  
A simple way to extend an HTML element
Simple "TIP" to "extend" an HTML element by adding functionality to it from an object-oriented perspective. In JavaScript, you can dynamically add attributes to an instance of an "object" that will only belong to that object. If a 'factory' function is defined that instantiates an object, adds (dynamically) the attributes we want, and returns the newly modified object, we have a quick way to implement some sort of "specialization."

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
Here just for fun

Comments and Discussions