mercuryyy mercuryyy - 3 years ago 161
Javascript Question

alphabetically sort an array of inputted words with javascript/jquery

I am new to javascript and jquery. I need help figuring out what is wrong with my code because it is not executing ".sort()" and ".join(", ") during the last steps...

I want the page to have a pop-up box where the user types in a place (inputs are stored in the array) and continues that until they type 'done', and then the page loads their list of places in alphabetical order with commas. I got the first part ok (the prompts and entering text), but my page doesn't load the entered material after entering 'done'. Below is my code:

<div id="outputPlaces"></div>

$(document).ready(function() {
var favPlaces = [];
var input = prompt("Please enter your favorite place or type done to stop entering places.");
while (input != 'done') {
input = prompt("Please enter another favorite place or type done to stop entering places.");
$('#outputPlaces').html = favPlaces.join(", ")



Answer Source

You can't set the HTML using assignment. The html function gets the HTML in the element. What you want is .text:

.text(favWords.join(", "))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download