Jquery . text printing only once

Asked

Viewed 32 times

2

$.getScript("func2.js", function() {
    $(".teste1").text("1");
    $(".teste2").text("2");
});

<div class="teste1" style="color: red"><div>
<div class="teste2"><div>

'Cause he only inserted it once?

3 answers

2

Because there is an error in your code, note that you have a comma, remove it that will solve.

Remove that comma at the end:

$(".teste1").text("1"),

To:

$(".teste1").text("1");
  • Sorry, I edited the question, the probelama is using the . getScript function

  • @Josimara try to close the Divs.

1

You have 3 errors in your code:

  • to close the Divs with /
  • lack the { in the opening of the function
  • you must use ; and not , to separate the lines

$(document).ready(function(){
    $(".teste1").text("1");
    $(".teste2").text("2");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="teste1" style="color: red"></div>
<div class="teste2"></div>

  • 1

    I hadn’t noticed! Thanks :) the error was in the div closing

1

I put your code on jsfiddle, clear removing the name of the script and works, just fixing the tags that are wrong:

<div class="teste1" style="color: red"><div>

Should be:

<div class="teste1" style="color: red"></div>

And

<div class="teste2"><div>

Should be

<div class="teste2"></div>

That is, the tags div are not being closed

  • I hadn’t noticed! Thanks :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.