how to get attribute’s value of selected option of a list by jquery

May 22, 2011

solution 1: var attrValue = $(‘#id :selected’).attr(‘attr_name’);
solution 2: var attrValue = $(“option:selected”,this).attr(‘attr_name’);
solution 3: var attrValue = $(“#id”).find(‘:selected’).attr(‘attr_name’);


Jquery: How to select more than one element

May 11, 2011

if you have two elements like:

<input id=”name” />

and

<span id=”address”>Berlin</span>

then using jquery you can select them like:

$(‘#name, #address’)

or

$(‘#name’).add(‘#address’)


Jquery: How to work with same class name elements event

May 11, 2011

Assumed that you have some links with same class. like:

<a class=”delete_user” href=”#”>delete</a>
<a class=”delete_user” href=”#”>delete</a>
<a class=”delete_user” href=”#”>delete</a>
.
.
.
<a class=”delete_user” href=”#”>delete</a>

on click event you want to delete the user info from database table. then just add a new attribute “user_id” here “user_id: is the primary key of “user” table. like:

<a user_id=”1″ class=”delete_user” href=”#”>delete</a>
<a user_id=”2″ class=”delete_user” href=”#”>delete</a>
<a user_id=”3″ class=”delete_user” href=”#”>delete</a>
.
.
.
<a user_id=”10″ class=”delete_user” href=”#”>delete</a>

then the Jquery code is:

(function(){

//DELETE USER
$(“.delete_user”).click(function(){
var user_id = $(this).attr(‘user_id’);
//here you delete operation using user_id
});

})();


Follow

Get every new post delivered to your Inbox.