Home >JavaScript >Examples in JavaScript

Examples in JavaScript

Making a whole table row a link is not easy. The tr tag itself cannot be wrapped in a link. And if you put links into all cells, the result may not be what you want. How to do it?

read more →

When you write a more complex script with jQuery (for example a configurator), helper attributes on its elements always come in handy. You will use id and class, and also your own attributes such as data-item-type or data-item-id.
It makes sense to select exactly one element by data-item-type and data-item-id together, which gives you exactly the element you want. How?

read more →

An image map is useful when you have an unusual shape and want its different parts to lead to different links.

read more →

It is not always a good idea to submit a form when the user presses Enter. One reason is that the form is validated too early – the user may not have gone through the whole form yet and so has not filled in a required field. How to block it and still keep Enter working in a textarea?

read more →

It is important to say that this protection will never be 100% effective, however you do it. Someone can always copy a visible address into a database by hand, or a robot can simply try common names such as info, support, help and so on. What matters is a well-configured spam filter on the server.

The very best is not to show the address anywhere. But if you need to show it, how do you protect it as well as possible?

read more →

A typical case is using anchors. You click an anchor, the page does not reload, and it would be useful to know which anchor is selected – so that you not only scroll to the block but also do something else.

Someone might think of the onload event, but it runs only when the document is first loaded. HTML5 offers the hashchange event, which solves this problem.

read more →

If you have a video (tested with a YouTube video) in a popup window, it can happen that you close the window but the video keeps playing. How to prevent that?

An older solution used the .get(0).stopVideo() function, but that works only when the video is loaded through the YouTube API.

read more →

How to sort a table built from div and span tags?

read more →

How to sort tables in the browser without reloading the page (= sorting without PHP)?

read more →

You need this when your website shows the content of another page in an iframe. If that content starts changing from the moment the page loads, it is important to delay it until you want. Ideally, after a click on a button or banner a popup opens and the animation of the page in the iframe starts from the beginning there – and not, for example, from the middle because it started when your website loaded, before the user clicked your button.

read more →

Load more articles