📄 Table of Contents

  • dynamically Add & Remove element with jQuery

Dynamically add and remove element with jQuery

Absolute File Paths

Example

Relative File Paths

In the following example, the file path points to a file in the images folder located at the root of the current web:

Example

Best Practice

It is best practice to use relative file paths (if possible).

When using relative file paths, your web pages will not be bound to your current base URL. All links will work on your own computer (localhost) as well as on your current public domain and your future public domains.

Event Handling on Buttons

<div class="buttons">
<button>Press 1</button>
<button>Press 2</button>
<button>Press 3</button>
</div>
const buttonContainer = document.querySelector('.buttons');
console.log('buttonContainer', buttonContainer);

buttonContainer.addEventListener('click', event => {
console.log(event.target.value)
})

--------------------------------------------------------------------
<form>
<input type="button" value="Start machine">
</form>
<p>The machine is stopped.</p>
const button = document.querySelector('input');
const paragraph = document.querySelector('p');

button.addEventListener('click', updateButton);

function updateButton() {
if (button.value === 'Start machine')
{
button.value = 'Stop machine';
paragraph.textContent = 'The machine has started!';
}
else
{
button.value = 'Start machine';
paragraph.textContent = 'The machine is stopped.';
}
}

Which ‘key’ has been clicked

$(document).ready(function(){
$(‘#email-to-share’).keypress(function (e) {
var key =
e.which;
if(key == 13){...}
});

The on() method attaches one or more event handlers for the selected elements.

$("p").on({
mouseenter: function(){
$(this).css("background-color", "lightgray");
},
mouseleave: function(){
$(this).css("background-color", "lightblue");
},
click: function(){
$(this).css("background-color", "yellow");
}
});

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store