Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object doesn't support property or method 'find' in jquery

Tags:

jquery

I have the references below in my form

<link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

I am trying find the contents of the title element from the below string.

var mytext = "<head><title>bad error</title></head>";
var err = mytext.find('title'); 

I am getting Object doesn't support property or method 'find' error.

My requirement is I want to get text between an element <title>.

like image 603
user1463065 Avatar asked Feb 11 '26 14:02

user1463065


1 Answers

find is jquery method, not string method. Wrap your HTML string in jquery.

Use text to get the innerText of an element.

$(mytext).find('title').text();

Example:

var mytext = "<head><title>bad error</title></head>";
var err = $(mytext).find('title').text();

alert(err);
like image 175
Tushar Avatar answered Feb 18 '26 14:02

Tushar



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!