I have a <div> that exists on a page and I need to make it so that when the user clicks outside of that element it will become hidden, but if the user clicks somewhere within the element, then it should stay. I tried using e.stopPropagation(); and e.preventDefault(); adding it to the click event of that certain DIV but that
Tag: javascript
Javascript selecbox.options to array?
From what I understand a option elements that popuate select elements in HTML are an array. So basically what i want to do is return an array string that is separated by commas. Tried to do selecbox.options.join(‘,’);, but got an error that its not supported; anyone have an idea why? Answer It is not an array. It is an HTMLCollection.
How to tell JavaScript to execute a function after an element has been loaded?
How to tell JavaScript to execute a function after an element has been loaded w/out any external library? Normally I have to bring the <script> tag after the element itself to work with DOM calls. Answer Well you can utilize the document.onload and window.onload methods For example:
what encoding this is?
can anyone tell me what encoding is applied on the chinese character, so that chinese characters are converted into this code or text and stored in mysql database : original chinese characters which are displayed in web page : on the web page there is a header function is used to make standard chinese chars as follow: Thanks… Answer When
Prepend text to beginning of string
What is the fastest method, to add a new value at the beginning of a string? Answer Wouldn’t this work for you?
Maximum size of a element
I’m working with a canvas element with a height of 600 to 1000 pixels and a width of several tens or hundreds of thousands of pixels. However, after a certain number of pixels (obviously unknown), the canvas no longer display shapes I draw with JS. Does anyone know if there’s a limit? Tested both in Chrome 12 and Firefox 4.
Why is my .data() function returning [ instead of the first value of my array?
I want to pass an array into a jQuery data attribute on the server side and then retrieve it like so: Why does this appear to alert ‘[‘ and not ‘a’ (see JSFiddle link) JSFiddle Link: http://jsfiddle.net/ktw4v/3/ Answer It’s treating your variable as a string, the zeroth element of which is [. This is happening because your string is not
Json file gives 403 error on server
I have a json file contianing data which I access through javascript. On my virtual MAMP server on mac It works, but on my online server when I load the HTML file I cant access the json file from javascript. I get 403 no permission for access error. Why? Answer If your production server is Linux based then please consider
Issue regarding live event
I was just reading http://api.jquery.com/event.stopPropagation/ Since the .live() method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events I was a bit confused with this statement, Can someone please explain me the same with some example? Answer Live method binds a handler to the document, and identifies
How do I detect “shift+enter” and generate a new line in Textarea?
Currently, if the person presses enter inside the text area, the form will submit. Good, I want that. But when they type shift + enter, I want the textarea to move to the next line: n How can I do that in JQuery or plain JavaScript as simple as possible? Answer Better use simpler solution: Tim’s solution below is better