i’m trying to figure out the code for the jquery selector test found at http://www.w3schools.com/jquery/trysel.asp?filename=trysel_basic&jqsel=p.intro,%23choose.
I’m getting error:
Uncaught Syntax error, unrecognized expression: “h1” jquery.js:4241
in Chrome developer tool when i enter h1 in the text box. By right it should highlight “Welcome to My Homepage” which is within <h1> tag.
Can someone point out on where i’m going wrong? Thank you.
The following is my code:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(":button").click(function(){
var hl_str= '"'+$(":text").val()+'"';
//document.write(hl_str);
$(hl_str).effect("highlight",{color:"ff0000"},3000);
});
})
</script>
</head>
<body>
<input type="text">
<input type="button" value="Edit and Click Me">
<h1>Welcome to My Homepage</h1>
<p class="intro">My name is Donald</p>
<p>I live in Duckburg</p>
<p>My best friend is Mickey</p>
Who is your favourite:
<ul id="choose">
<li>Goofy</li>
<li>Mickey</li>
<li>Pluto</li>
</ul>
</body>
</html>
You don’t need the quotes when building the “hl_str” string.
Try: