Linebreak In JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hubs Hubs
    New Member
    • Mar 2012
    • 2

    Linebreak In JavaScript

    I have these line of JavaScript:



    Code:
    $(document).ready(function () {
    	/*$('#first').focus();
    	$(this).keyup(function (e) {
    		if (e.keyCode == 13) {
    			generate();
    		}
    	});*/
    		});
    function generate() {
    	if($("input[name='name']").val().length > 1) {
    		fi = $("input[name='name']").val().substring(0,1).toUpperCase();
    		var sl = ["Cool "];
    		var sl2 = ["Hand "];
    		var sl3 = ["Luke",];
    	
    		{
    			var i = Math.floor(Math.random() * sl.length);
    			var j = Math.floor(Math.random() * sl2.length);
    			var k = Math.floor(Math.random() * sl3.length);
    			var nick = sl[i] +   sl2[j] +   sl3[k];
    		}
    		{
    		$("#answer").text("Your Name Is: " +nick);
    		$("#answer").fadeIn("slow");
    		} 
    	}
    }


    I would like for it to return:

    Your Name Is:
    Cool Hand Luke


    I want the "Cool Hand Luke" to be on a separate line but I don't know how to put a linebreak in the .text string. Is this something somebody could tell me how to do?
    Last edited by Dormilich; Mar 11 '12, 01:00 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    since you want to output HTML, you would use a HTML break (<br>)

    Comment

    • Hubs Hubs
      New Member
      • Mar 2012
      • 2

      #3
      Thanks for the response Dormilich

      Where in the line:
      Code:
      $("#answer").text("Your Name Is: " +nick);
      Do I put (<br>)
      Last edited by Dormilich; Mar 12 '12, 05:39 PM.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        where would you put it?

        Comment

        Working...