asked on
<a id="contactLink" data-link="contact"></a>
$("A[data-link]").on("click" , (function(e) {
var targetData = $(this).attr("data-link");
document.querySelector('#' + targetData).scrollIntoView({block: 'start', behavior: 'smooth'}
});
ASKER
ASKER
ASKER
ASKER
document.getElementById('mylist').innerHTML = myEl.map(id => `<li><a id='${id}Link' href='#${id}'>${id}</a></li>`).join('');
or even without the ID if you do not need itdocument.getElementById('mylist').innerHTML = myEl.map(id => `<li><a href='#${id}'>${id}</a></li>`).join('');
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY
ASKER
const homeLink = document.getElementById('h
homeLink.onclick = function(e) {
e.preventDefault();
document.querySelector('#h
}
const servLink = document.getElementById('s
servLink.onclick = function(e) {
e.preventDefault();
document.querySelector('#s
}
const teamLink = document.getElementById('t
teamLink.onclick = function(e) {
e.preventDefault();
document.querySelector('#t
}
const conLink = document.getElementById('c
conLink.onclick = function(e) {
e.preventDefault();
document.querySelector('#c
}
Instead of repeating the functions over and over how
might I write one function that could be called by the anchor onclick events?