Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - not working with input type search

I have a field with input type search

When I try to select that with jQuery I get VM535 jquery-git.js:1529 Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: search

Check the fiddle - Fiddle

How do I select that field? (note: I do not have any unique class or id applied to that field, actually it's plugin generated.)

Actually I am using jQuery DataTable plugin and I want to add a Go button just besides the search box. For this I am trying this workaround - to select the search box with jQuery and add button besides it with insertAfter method. Please suggest me if there is any other way for this.

like image 268
Half Blood Prince Avatar asked Jun 01 '16 11:06

Half Blood Prince


3 Answers

You can use attribute selector in such cases. Try this:

alert($('input[type="search"]').val());

Working example here: https://jsfiddle.net/ashishanexpert/dsye8b2x/1/

like image 130
Ashish Kumar Avatar answered Oct 03 '22 08:10

Ashish Kumar


input:search is not a valid selector(not listed in Selectors section in the docs)

Use Attribute Equals Selector input[type="search"]

alert($('input:text').val());
alert($('input[type="search"]').val())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" value="text">
<br/>
<input type="search" value="search">
<br/>
like image 23
Rayon Avatar answered Oct 03 '22 06:10

Rayon


you were close, do this: alert($('input[type="search"]').val())

like image 21
somdow Avatar answered Oct 03 '22 06:10

somdow