Clearing my form inputs after submission

Your form is being submitted already as your button is type submit. Which in most browsers would result in a form submission and loading of the server response rather than executing javascript on the page. Change the type of the submit button to a button. Also, as this button is given the id submit, it … Read more

jQuery replace one class with another

To do this efficiently using jQuery, you can chain it like so: For simplicities sake, you can also do it step by step like so (note assigning the jquery object to a var isnt necessary, but it feels safer in case you accidentally remove the class you’re targeting before adding the new class and are … Read more

Load Image from javascript

you can just append another hidden img element and swap them in onload event. Or use single image element and use javascript like: this code should preload the image and show it when it’s ready

Extract hostname name from string

I recommend using the npm package psl (Public Suffix List). The “Public Suffix List” is a list of all valid domain suffixes and rules, not just Country Code Top-Level domains, but unicode characters as well that would be considered the root domain (i.e. www.食狮.公司.cn, b.c.kobe.jp, etc.). Read more about it here. Try: Then with my … Read more

How do I select text nodes with jQuery?

jQuery doesn’t have a convenient function for this. You need to combine contents(), which will give just child nodes but includes text nodes, with find(), which gives all descendant elements but no text nodes. Here’s what I’ve come up with: Note: If you’re using jQuery 1.7 or earlier, the code above will not work. To fix this, … Read more