Is it possible put parameter in html form another javascript?


  • GNU/Linux

    I exaplain bettere. I have one controller, a page html and another file javascript.
    The controller pass the parameters to html page:

               data={items:{message:'home',dog:'cat'});
    	res.render('-------', data);
    

    In the html page I get parameters in this way:
    <div id="fish">
    <label>{items.message}</label>
    </div>

    Now suppose to have a javascript that when I click on a button do this:
    .....
    var div=$('#fish');
    var label=$('<label>');
    //In this label that I attacck to html page I want to have the other parameter that I //passed from the controller. I think I don't write a correct code here:
    label.text(items.dog);
    label.append('</label>);
    div.append(label);

    Bu the code doesn't work. I can read items.dog like value. My question is it possibile something like this or I can' because html is execute firt respect javascript or something? Anyone can help me?

    });


  • Community Rep

    in the client, those values are stored in ajaxify.data

    For your jQuery, you don't append a closing tag, it does that automatically. When you want to insert the element into the div, you need to use appendTo(). Also, unless your label has additional data, I recommend using html() instead of text().

    Here's a fiddle. I also added an ID to the new label so it isn't added more than once.




Star

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.