Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom css select boxes using jquery

Tags:

jquery

css

select

I'm using this script http://mondaybynoon.com/2009/02/23/creating-custom-form-elements-using-jquery-selects/ to create custom css select boxes in my page. Javascript code that is used to apply the css styles on selectboxes, uses their id as a parameter:

$(document).ready(function() {
 $('#cont').selectbox({debug: true});
});

<select id="cont" name="cont" tabindex="1">
<option value="1">aaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
</select>

Can I somehow use just the "name" attribute of select boxes and not the "id"??? Is this possible?

like image 750
zekia Avatar asked Nov 21 '25 08:11

zekia


2 Answers

you can use the attribute selector to selct via name

e.g.

$('select[name="cont"]').selectbox({debug: true});
like image 100
CeejeeB Avatar answered Nov 24 '25 00:11

CeejeeB


Sure, to base your selector off of the name-attribute, simply do the following:

$("[name='nameHere']");
like image 42
Sampson Avatar answered Nov 23 '25 23:11

Sampson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!