0

What am I doing wrong that this jQuery isn't doing anything?

<head>
    <title></title>
    <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
</head>

In body

<p id="somediv"></p>
<script>
var arr = ["1", "2", "3", "4"];
$(document).ready(function(){
$("somediv").html("before loop");
$.each(arr, function(index, value) {
       $("somediv").html(value);
   });
});
</script>

3 Answers 3

1
$("#somediv").html(value);

You are missing the # in front of your ID selector

Sign up to request clarification or add additional context in comments.

Comments

1

You are missing id selector # in all cases:

$("#somediv").html(value);

Comments

1

You missed # prefix in all in your code. if you put .html() means it display last value only visible in your case use append

$("#somediv").append(value);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.