Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using JQuery().text() returning int with string

Tags:

jquery

I'm getting a return value for this query that doesn't make sense.

code is:

var option = $(":selected").text();

result:

10   Activity

can anyone tell me why I'm getting back a 10 and spaces and how to get rid of them?

html:

<select name="datagrid_filter" onchange="startFilter(this);">
<option>All</option>
<option disabled="true">Assignment:</option>
<option disabled="true">Client:</option>
<option disabled="true">Type:</option>
    <option class="type" value="Activity"> &nbsp Activity</option>
    <option class="type" value="Alert"> &nbsp Alert</option>
    <option class="type" value="Lead"> &nbsp Lead</option>
    <option class="type" value="Notification"> &nbsp Notification</option>
</select>
like image 989
user2671355 Avatar asked May 30 '26 17:05

user2671355


1 Answers

Working Demo Here

You can remove unwanted spaces using the the function:

jQuery.trim( str )

regarding the "10" if you have other <select> the page, to avoid problems, refer directly to the <select name="datagrid_filter"> by name

$("select[name='datagrid_filter'] option:selected").text()
like image 112
ReDEyeS Avatar answered Jun 02 '26 09:06

ReDEyeS