Half Blood Prince Half Blood Prince - 6 months ago 28
Javascript Question

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.

Answer

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/>

Comments