Skip to content
Advertisement

How to swap DOM child nodes in JavaScript?

What is the easiest way to swap the order of child nodes? For example I want childNode[3] to be childNode[4] and vice-versa. Answer There is no need for cloning. You can just move one node before the other. The .insertBefore() method will take it from its current location and insert it somewhere else (thus moving it): You get the parent

Disable scrolling on “

Is it possible to disable the scroll wheel changing the number in an input number field? I’ve messed with webkit-specific CSS to remove the spinner but I’d like to get rid of this behavior altogether. I like using type=number since it brings up a nice keyboard on iOS. Answer Prevent the default behavior of the mousewheel event on input-number elements

Regexp Matching Hex Color Syntax (and Shorten form)

Well, I’m pretty new on regex and in particular on JavaScript regexp. I’m looking for making a regexp that match the hex color syntax (like #34ffa6) Then I looked at the w3school page: Javascript RegExp Object Then that’s my regexp: It seems to work but, if I want it to match also the “short hex color syntax” form? (like #3fa),

How to use typed variables in javascript?

Is there any way to use typed variables in javascript? Like integer, string, float… Answer JavaScript variables are not typed. JavaScript values are, though. The same variable can change (be assigned a new value), for example, from uninitialized to number to boolean to string (not that you’d want to do this!):

Pass a string parameter in an onclick function

I would like to pass a parameter (i.e. a string) to an Onclick function. For the moment, I do this: with result.name for example equal to string “Add”. When I click on this button, I have an error that says that “Add is not defined”. Since this function call works perfectly with a numeric parameter, I assume that it has

detecting a redirect with javascript – how?

Is there any way to detect whether a webpage is going to redirect me to another, knowing its URL? I mean the situation when you type URL in a text field and the script examines it for 3xx redirections. Answer Yes, you can do this quite easily in Javascript. It’d look something like: Unfortunately, this only works on your own

Falling hearts animation for browsers

Recently I have downloaded falling hearts animation from this . I have pasted the code below too. It simply displays a heart in my page.and falling hearts animation is not working.I am not able to identify the problem. will anyone tell me what changes I have to made in order to get the hearts falling animation.or is there any other

Sort an array by a preferred order

I’d like to come up with a good way to have a “suggested” order for how to sort an array in javascript. So say my first array looks something like this: Now all I care about, is that the sorted results starts out in this order: After that, I Want the remaining values to be presented in their original order.

Advertisement