Skip to content

Instantly share code, notes, and snippets.

View shameersn's full-sized avatar
😃
I am learning every day ...

Shameer S N shameersn

😃
I am learning every day ...
View GitHub Profile
@shameersn
shameersn / gist:399107ad9a9f60de975a
Created November 24, 2015 09:16
To get the value of the selected radioName item
To get the value of the selected radioName item of a form called 'myForm':
$('input[name=radioName]:checked', '#myForm').val()
@shameersn
shameersn / how to pass this element to javascript onclick function
Created November 10, 2015 05:21
how to pass this element to javascript onclick function
<a onclick="Data(this)">This Month</a>
function Data(el)
{
$(el).parent().addClass('active') ;
//el can used for this
}
@shameersn
shameersn / gist:43c129056a080375a329
Created November 9, 2015 04:53
how to select a parent element in jquery with a particular class
how to select a parent element in jquery with a particular class
Use .closest() with a selector:
var selected = $('#id').closest('.className');
@shameersn
shameersn / how to add access-control-allow-origin header in php
Created November 6, 2015 05:18
how to add access-control-allow-origin header in php
header("Access-Control-Allow-Origin: *");
@shameersn
shameersn / gist:98f64d9562bada18f5f7
Created November 5, 2015 09:51
how to allow input type=file to accept only image files
The accept attribute is incredibly useful. It is a hint to browsers to only show files that are allowed for the current input. While it can typically be overridden by users, it helps narrow down the results for users by default, so they can get exactly what they're looking for without having to sift through a hundred different file types.
Usage
Note: These examples were written based on the current specification and may not actually work in all (or any) browsers. The specification may also change in the future, which could break these examples.
h1 { font-size: 1em; margin:1em 0; }
h1 ~ h1 { border-top: 1px solid #ccc; padding-top: 1em; }
<h1>Match all image files (image/*)</h1>
<p><label>image/* <input type="file" accept="image/*"></label></p>
@shameersn
shameersn / gist:0197352f3b0daf0666ef
Created November 5, 2015 07:03
jquery how to get data attribute value of selected option
<select>
<option data-id="1">one</option>
<option data-id="2">two</option>
<option data-id="3">three</option>
</select>
You need to find the selected option:
$(this).find(':selected').data('id')
or
@shameersn
shameersn / gist:18dae1a01556a7bcc8d3
Last active November 5, 2015 06:33
jquery how to catch select box change event
$( ".target" ).change(function() {
alert( "Handler for .change() called." );
});
//The change event is sent to an element when its value changes. This event is limited to <input> elements, <textarea> boxes and <select> elements.