سؤال

I'm trying to seperate a list with a line break but neither "\n" nor a br tag are working. Anybody know why?

var c_list=['One','Two','Three']
for (var x in c_list){
    holder_string += c_list[counter]
    holder_string += "\n"
    counter++
    $("#list").text(holder_string);
}
هل كانت مفيدة؟

المحلول

\n isn't really showed in the browser, other than in the source, and <br /> doesn't work in text() as it doesn't accept html, html() does

var c_list=['One','Two','Three']
for (var x in c_list){
    holder_string += c_list[counter]
    holder_string += "<br />"
    counter++
    $("#list").html(holder_string);
}

Note that you could just do

$("#list").html( c_list.join('<br />') );
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top