Object doesn't support property or method "find" in jquery
I have links 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 to find the content of the title element from the line below.
var mytext = "<head><title>bad error</title></head>";
var err = mytext.find('title');
I am getting error Object doesn't support property or method 'find'
.
By my requirement I want to get the text between the element <title>
.
+3
source to share
3 answers
The problem is what mytext
is the string. Strings do not have a search method. You want to instantiate jQuery and use it. If your string really looks like you sent it, the jQuery parsing result will already be a header element, and all you have to do is read the text:
var mytext = $("<head><title>bad error</title></head>");
var err = mytext.text();
alert(err);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
+1
source to share