What is event bubbling and capturing?

Event bubbling and capturing are two ways of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. The event propagation mode determines in which order the elements receive the event. With bubbling, the event is first captured and … Read more

jQuery setTimeout() Function [duplicate]

The problem is that inside the setTimeout() call, this doesn’t refer to the button. You need to set a variable to keep the reference to the button. I’ve created a sample below. See how I use the variable named $this. UPDATE: Now with modern browsers supporting Arrow Functions, you can use them to avoid altering the this context. See updated snippet below.

jQuery.click() vs onClick

Using $(‘#myDiv’).click(function(){ is better as it follows standard event registration model. (jQuery internally uses addEventListener and attachEvent). Basically registering an event in modern way is the unobtrusive way of handling events. Also to register more than one event listener for the target you can call addEventListener() for the same target. http://jsfiddle.net/aj55x/1/ Why use addEventListener? (From MDN) addEventListener is the way to register an event listener as specified in W3C DOM. Its … Read more

How can you encode a string to Base64 in JavaScript?

You can use btoa() and atob() to convert to and from base64 encoding. There appears to be some confusion in the comments regarding what these functions accept/return, so… btoa() accepts a “string” where each character represents an 8-bit byte – if you pass a string containing characters that can’t be represented in 8 bits, it will probably break. This isn’t a … Read more

How can I scroll to an element using jQuery?

JavaScript answer If you would like to scroll to an element smoothly with “pure JavaScript” you could do something like this: More information is here: Element.scrollIntoView() NOTE: Please see Can I use… Support tables for HTML5, CSS3, etc. for the latest browser support… jQuery answer If you would like to scroll to an element smoothly using jQuery then … Read more

What is the way of declaring an array in JavaScript?

The preferred way is to always use the literal syntax with square brackets; its behaviour is predictable for any number of items, unlike Array‘s. What’s more, Array is not a keyword, and although it is not a realistic situation, someone could easily overwrite it: However, the larger issue is that of consistency. Someone refactoring code could come across … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)