Skip to content

Tag: html

Changing website favicon dynamically

I have a web application that’s branded according to the user that’s currently logged in. I’d like to change the favicon of the page to be the logo of the private label, but I’m unable to find any code or any examples of how to do this. Has anybody successfully done this before? I&#821…

Invoking JavaScript code in an iframe from the parent page

Basically, I have an iframe embedded in a page and the iframe has some JavaScript routines I need to invoke from the parent page. Now the opposite is quite simple as you only need to call parent.functionName(), but unfortunately, I need exactly the opposite of that. Please note that my problem is not changing…

How can I change an element’s class with JavaScript?

How can I change the class of an HTML element in response to an onclick or any other events using JavaScript? Answer Modern HTML5 Techniques for changing classes Modern browsers have added classList which provides methods to make it easier to manipulate classes without needing a library: Unfortunately, these …

When should I use Inline vs. External Javascript?

I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance. What is the general practice for this? Real-world-scenario – I have several html pages that need client-side form validation. For this I use a jQuery plug…

Highlight a word with jQuery

I basically need to highlight a particular word in a block of text. For example, pretend I wanted to highlight the word “dolor” in this text: How do I convert the above to something like this: Is this possible with jQuery? Edit: As Sebastian pointed out, this is quite possible without jQuery &#821…

How can I remove a child node in HTML using JavaScript?

Is there a function like document.getElementById(“FirstDiv”).clear()? Answer To answer the original question – there are various ways to do this, but the following would be the simplest. If you already have a handle to the child node that you want to remove, i.e. you have a JavaScript variab…