Try to search your question here, if you can't find : Ask Any Question Now ?

jQuery element selector returns a list instead of an HTML tag

HomeCategory: stackoverflowjQuery element selector returns a list instead of an HTML tag
Avatarcraig asked 1 month ago

I have created an HTML document and when I use jQuery I am getting an unexpected result instead of seeing the HTML tag in Google Chrome console.

It worked when I was using Javascript.

Is there a setting I am missing?

Here is my HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>jQuery Demo</title>
    <!-- <script  src="lib/jquery-3.4.1.min.js"></script> -->
    <script  src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>

<body>

    <h1>jQuery Demo</h1>

    <ul>
        <li>Newt</li>
        <li>Howler Monkey<a href="monkey.com"> Monkey.com</a></li>
        <li id="adorable">Pine Marten</li>
    </ul>

    <a href="https://www.google.com">GOOGLE</a>
</body>

</html>

The following jQuery code in Google console

$("h1")

should result in

<h1>jQuery Demo</h1>

but the result is just a list and 0 gives me the entire object.

The initial open and last close double quotes of each line are there so I can post it as is.

"$("h1")"

"k.fn.init [h1, prevObject: k.fn.init(1)]"

"0: h1"

"length: 1"

"prevObject: k.fn.init [document]"

"__proto__: Object(0)"
1 Answers
Best Answer
AvatarMikhail answered 1 month ago
Your Answer

10 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com