HOW TO CREATE JAVASCRIPT FRAMEWORK .insert() BY YOURSELF | JAVASCRIPT | INSERTED TEXT OR HTML
What is framework .insert() ?
The framework .insert() is used for inserting "text" or "HTML". Usually, In javascript we using InnerHTML and appendChild(), in this tutorial we learn to insert text or html using one of them in framework.
How to create javascript framework .insert() ?
The demo below is easy in use for presentation the framework .insert(). You enter text or HTML and click insert, and it's will displayed on div element. On this demo the system using insert() to inserting them. We will discuss one by one after you try this demo.
Remember in this article we not discuss framework .click(). You have to read about framework click() on this blog before you read all article about framework, because we using .click() to call .insert() or other framework.
Step by step to create framework .insert() :
1. First, create a HTML file. Next, write a form with button and a div element (Don't forget to add id and class).
Example:
2. After that, create a css file to make the form, button and div element more cool.
Example:
3. And than, create a framework .insert(). Remember We not discuss an article about framework click(), we direct to discuss the framework .insert().
Create two variable, that is: var KarimMuhaiminBlog (or other name what you like) and var $ (dollars).
Example:
4. And than, insert a function with selector into KarimMuhaiminBlog variable.
Example:
5. Next, insert the DOM ( Document Object Model) into the function. Use document.querySelector() or document.getElementById(). Don't forget to create e or element variable.
Example:
6. After that, create an object and function with selector but use different name, We direct to this.insert() (to create object) = function(text){} (to create a function).
Example:
7. And than, insert element.innerHTML or element.appendChild() ( not recomended) into this.insert = function(text){ code here } .
Example:
8. Next, if the framework is callback, create a new function using var $.
Example:
9. Finally, test your framework code using
$('button id or class').click(function() {
var el = document.getElementById('txt').value;
el ? $('id or class').insert(el) : $('id or class').insert('Enter text or HTML');
;
});
. this code is like the demo above, but if you want to insert text or HTML on load you can test using this code
$('#myD').insert('Enter your text or HTML');
.
Example:
What is the full code of this tutorial ?
You can copy the code below for free. Try it yourself.
What's next ?
How to create javascript framework .append() by yourself (coming soon)
What is framework .insert() ?
The framework .insert() is used for inserting "text" or "HTML". Usually, In javascript we using InnerHTML and appendChild(), in this tutorial we learn to insert text or html using one of them in framework.
How to create javascript framework .insert() ?
The demo below is easy in use for presentation the framework .insert(). You enter text or HTML and click insert, and it's will displayed on div element. On this demo the system using insert() to inserting them. We will discuss one by one after you try this demo.
Remember in this article we not discuss framework .click(). You have to read about framework click() on this blog before you read all article about framework, because we using .click() to call .insert() or other framework.
Step by step to create framework .insert() :
1. First, create a HTML file. Next, write a form with button and a div element (Don't forget to add id and class).
Example:
|
2. After that, create a css file to make the form, button and div element more cool.
Example:
|
3. And than, create a framework .insert(). Remember We not discuss an article about framework click(), we direct to discuss the framework .insert().
Create two variable, that is: var KarimMuhaiminBlog (or other name what you like) and var $ (dollars).
Example:
|
4. And than, insert a function with selector into KarimMuhaiminBlog variable.
Example:
|
5. Next, insert the DOM ( Document Object Model) into the function. Use document.querySelector() or document.getElementById(). Don't forget to create e or element variable.
Example:
|
6. After that, create an object and function with selector but use different name, We direct to this.insert() (to create object) = function(text){} (to create a function).
Example:
|
7. And than, insert element.innerHTML or element.appendChild() ( not recomended) into this.insert = function(text){ code here } .
Example:
|
8. Next, if the framework is callback, create a new function using var $.
Example:
|
9. Finally, test your framework code using
$('button id or class').click(function() {
var el = document.getElementById('txt').value;
el ? $('id or class').insert(el) : $('id or class').insert('Enter text or HTML');
;
});
. this code is like the demo above, but if you want to insert text or HTML on load you can test using this code
$('#myD').insert('Enter your text or HTML');
.
Example:
|
What is the full code of this tutorial ?
You can copy the code below for free. Try it yourself.
What's next ?
How to create javascript framework .append() by yourself (coming soon)
Komentar
Posting Komentar