jQuery Scroll to Div

Check this link: http://css-tricks.com/snippets/jquery/smooth-scrolling/ for a demo, I’ve used it before and it works quite nicely.

The preferred way of creating a new element with jQuery

The first option gives you more flexibilty: And of course .html(‘*’) overrides the content while .append(‘*’) doesn’t, but I guess, this wasn’t your question. Another good practice is prefixing your jQuery variables with $:Is there any specific reason behind using $ with variable in jQuery Placing quotes around the “class” property name will make it more compatible with less flexible browsers.

if-not condition fails (jQuery)

You need to check the number of elements found, as jQuery returns an empty collection in the event of no elements being found (which evaluates to a truthy value in the if statement): I’d suggest testing against 0 explicitly, rather than relying on a falsey value, though:

How to get current date in jQuery?

Date() is not part of jQuery, it is one of JavaScript’s features. See the documentation on Date object. You can do it like that: See this jsfiddle for a proof. The code may look like a complex one, because it must deal with months & days being represented by numbers less than 10 (meaning the strings will have one char instead of … Read more

Setting and getting localStorage with jQuery

You said you are attempting to get the text from a div and store it on local storage. Please Note: Text and Html are different. In the question you mentioned text. html() will return Html content like <a>example</a>. if you want to get Text content then you have to use text() instead of html() then the result will be example instead of <a>example<a>. Anyway, I am using your … Read more

Attaching ‘onclick’ event to D3 chart background

The event isn’t actually overridden, but both are triggered — the onclick handler for the SVG and for the bar. To prevent this, use the .stopPropagation() method (see the documentation). The code looks like this: Complete example here. Compare with the behaviour with stopping the propagation of the event here.

How to read data From *.CSV file using javascript?

NOTE: I concocted this solution before I was reminded about all the “special cases” that can occur in a valid CSV file, like escaped quotes. I’m leaving my answer for those who want something quick and dirty, but I recommend Evan’s answer for accuracy. This code will work when your data.txt file is one long string of comma-separated entries, with … Read more