scrollToElement function using javascript

Advertisements this javascript content: function scrollToElement(elementSelector, instance = 0) { const elements = document.querySelectorAll(elementSelector); if (elements.length > instance) { elements[instance].scrollIntoView({ behavior: "smooth" }); } } const link1 = document.getElementById("link1"); const link2 = document.getElementById("link2"); const link3 = document.getElementById("link3"); link1.addEventListener("click", () => { scrollToElement(".header"); }); but i not understand this and why it used instance and what… Read More scrollToElement function using javascript

How to remove an element that has been modified by outerHTML

Advertisements I have an element in the DOM that I update its HTML using outerHTML property, but I can’t remove it using a method like remove(). <div id="element">Element</div> <div id="remove">Removed element</div> const element = document.getElementById("element"); const removedElement = document.getElementById("remove"); element.outerHTML = "<div>First</div>"; element.remove(); removedElement.remove(); In my example, element gets updated using outerHTML, but I can’t… Read More How to remove an element that has been modified by outerHTML

Setting colspan with Javascript on certain td (without any id)

Advertisements I need to apply some CSS/JS on an existing web page. Within it there is <tr foodtablesupper> <td class="subheader" colspan="3"> Upper Floor </td> </tr> <tr foodchoice> <td class="dish-1"> Coleslaw </td> <td class="dish-2"> Porridge </td> </tr> <tr foodtablesupper> <td class="subheader" colspan="3"> Mezzanine Floor </td> </tr> I need to change the colspan to 4. How can… Read More Setting colspan with Javascript on certain td (without any id)

How to delete a range of rows using javascript (Vanilla or JQuery)

Advertisements I need to delete table rows in range from row with an ID "#deleteFirstRow" to row with an ID "#deleteLastRow". But all the other rows out of these two IDs should remain. NB: I tried to search posted answers but did not get any working solution. Please help! This is my table: <table> <tr>doNotDeleteRow</tr>… Read More How to delete a range of rows using javascript (Vanilla or JQuery)

Unable to edit text in HTML without changing CSS/styling

Advertisements I’m unable to edit a h1 tag without changing the css. Here is the string without the javascript: Here is the string with the javascript: I’m not having this problem elsewhere. THe rest of the code snippets were properly manipulated by the JS code. Here is the HTML and JS snippets: document.getElementById(‘currentContact’).innerText = state.translate(‘test’);… Read More Unable to edit text in HTML without changing CSS/styling