How to return a javascript function to an HTML?

Asked

Viewed 1,432 times

2

Guys took the following function in Javascript (jQuery):

      function CustomAlert() {
            this.show = function (nome) {


            };

        }
        var Alert = new CustomAlert();

        $(document).ready(function () {
            Alert.show('meu nome e hugo');
        });

How do I get it back, write the screen the following HTML:

<div class="nome">meu nome e hugo</div>
  • Your question is unclear... you want to create a name function Alert (with the first large letter) and make it write in HTML? You can explain better what you want to do, how you call the function and the HTML you have?

  • @Sergio Ok, I’m sorry. I edited my question, give a look now please.

  • Tries: document.getElementsByClassName("nome")[0].innerHTML = 'Meu Nome é Hugo';

1 answer

4


Just direct the message using one of the following Jquery codes, both work but with a slight difference see:

$("div.nome").html('meu nome é <b>hugo</b>');//a tag <b> é renderizada

Can also be used with "text":

$("div.nome").text('meu nome é <b>hugo</b>');//a tag <b> é string e não renderiza.

More information can be found in the links below:

http://api.jquery.com/html/

http://api.jquery.com/text/

Good luck!

Browser other questions tagged

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