You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" href="jquery-ui.min.css" type="text/css" /><linkhref="style.css" rel="stylesheet" type="text/css" /></head><body><header><h1id="head">Click a list item to replace this text</h1></header><ulid="list"><li><a>First Item</a></li><li><a>Second Item</a></li><li><a>Third Item</a></li><li><a>Fourth Item</a></li><li><a>Fith Item</a></li></ul><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="jquery-ui.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
varitems=document.getElementById("list").getElementsByTagName("li");varhead=document.getElementById("head");varposNumber=0;for(s=0;s<items.length;s++){items[s].addEventListener("click",activator);}functionactivator(){head.innerHTML=this.innerHTML;for(a=0;a<items.length;a++){items[a].classList.remove("active");}this.classList.add("active");}//+= this is equel to append.But this not in this code.
Output
2. JavaScript Design Partterns snippets
Example 0
HTML
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" type="text/css" href="style.css"></head><body><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" type="text/css" href="style.css"></head><body><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" href="jquery-ui.min.css" type="text/css" /><linkhref="style.css" rel="stylesheet" type="text/css" /></head><body><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="jquery-ui.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
JavaScript
functionperson(name,favColor){console.log("My name is "+name+" and my favorite color "+favColor);}varname="joker";varfavColor="Red";person("kuna","Blue");person(name,favColor);//This is kind of OOP Progarmming.
Output
Example 1
HTML
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" href="jquery-ui.min.css" type="text/css" /><linkhref="style.css" rel="stylesheet" type="text/css" /></head><body><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="jquery-ui.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
JavaScript
functionperson(name,favColor){console.log("My name is "+name+" and My Favorite Color is "+favColor);}varkuna={name: "Kuna",favColor:"Blue"}person(kuna.name,kuna.favColor);
Output
Example 2
HTML
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" href="jquery-ui.min.css" type="text/css" /><linkhref="style.css" rel="stylesheet" type="text/css" /></head><body><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="jquery-ui.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
JavaScript
varJoker={name: "Joker Hacker",favColor: "red",greet: function(){console.log("My name is "+this.name+" and my favoriate color is "+this.favColor);}}Joker.greet();
Output
Example 3
HTML
<!DOCTYPE html><html><head><title>This is the title</title><linkrel="stylesheet" href="jquery-ui.min.css" type="text/css" /><linkhref="style.css" rel="stylesheet" type="text/css" /></head><body><scriptsrc="jquery-3.2.1.min.js" type="text/javascript"></script><scriptsrc="jquery-ui.min.js" type="text/javascript"></script><scriptsrc="js.js" type="text/javascript"></script></body></html>
JavaScript
functionPerson(fullName,favColor){//Always use upper-case for blue Prints.Not Improtant.this.name=fullName;this.favoriteColor=favColor;this.greet=function(){console.log("My name is "+this.name+" and my favorite Color is "+this.favoriteColor+".");}}varjoker=newPerson("Joker Hacker","Red");varkuna=newPerson("Kunarakulan","Blue");joker.greet();kuna.greet();