Jquery .text printing only once

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

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

Why did he only enter once?

    
asked by anonymous 17.05.2018 / 19:33

3 answers

2

Because you have an error in your code, notice that it has a comma, remove it and it will solve.

Remove this comma at the end:

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

To:

$(".teste1").text("1");
    
17.05.2018 / 19:40
1

You have 3 errors in your code:

  • close divs with /
  • { is missing at function opening
  • You should use ; and not , to separate 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><divclass="teste1" style="color: red"></div>
<div class="teste2"></div>
    
17.05.2018 / 19:46
1

I put your code in jsfiddle , clear removing the name of the script and it works, only correcting the tags that are wrong:

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

Should be:

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

E

<div class="teste2"><div>

Should be

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

That is, the div tags are not being closed

    
17.05.2018 / 19:46