tags:

views:

26

answers:

3

ASP.NET is changing id, name values according to control's parent control name. That's why i am searching id with JQUERY as below.

// $ is looking to the end of "id" attribute of input elements
$("input[id$='cbAddToNews']")

Only one element is returning by jQuery. But when i want to change the attribute, I'm using this syntax:

$($("input[id$='cbAddToNews']")[0]).show()

Is there any way to do this without wrapping it with $(...[0]) ?

A: 

$("input[id$='cbAddToNews']:first").show()

Read more about this here

Matt
+1  A: 

You should rather find out the actual ID being assigned to it via the ClientID property instead of using $=.

Also, if jQuery is already only returning one element, why do you try to limit it to the first one separately?

Matti Virkkunen
+1  A: 

You can use classes instead. Assign a class to your ASP.NET element using CssClass="classname".

use $('input.classname') to select the element in jQuery.

James Westgate