jQuery – Illegal invocation

I think you need to have strings as the data values. It’s likely something internally within jQuery that isn’t encoding/serializing correctly the To & From Objects. Try: Notice also on the lines: You don’t need the jQuery wrapper as To & From are already jQuery objects.

How do I pass the this context to a function?

Javascripts .call() and .apply() methods allow you to set the context for a function. Now you can call: Which would alert FOO. The other way around, passing obj_b would alert BAR!!. The difference between .call() and .apply() is that .call() takes a comma separated list if you’re passing arguments to your function and .apply() needs … Read more

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