Concepts of jQuery

📄 Table of Contents
- how to run a ruby file
- dynamically Add & Remove element with jQuery
Dynamically add and remove element with jQuery

Absolute File Paths
An absolute file path is the full URL to a file:
Example
<img src=”https://www.w3schools.com/images/picture.jpg" alt=”Mountain”>
Relative File Paths
A relative file path points to a file relative to the current page.
In the following example, the file path points to a file in the images folder located at the root of the current web:
Example
<img src=”/images/picture.jpg” alt=”Mountain”>
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");
}
});