Jump to content
Adamhumbug

Split string into new lines at comma -> update text

Recommended Posts

Hi,

I have the following code that populates a modal

		$('#userDeleteConfirmationModal').on('show.bs.modal', function(event) {
		// Button that triggered the modal
		var button = $(event.relatedTarget)
		//data elements
		var userid = button.data('userid')
		var activesheets = button.data('activesheets').split(", ").join("\n")
		console.log(activesheets);
		var modal = $(this)
		modal.find('#deleteUserConfLabel').text(userid)
		modal.find('#active-sheets-label').text('This user has the following active sheets')
		modal.find('#active-sheets').text(activesheets)

the console log outputs

Job 1

Job 2

but the text.(activesheets) shows them on the same line when they hit the page.

Any ideas?

Share this post


Link to post
Share on other sites

You need "<br>" for newlines in an html document ("\n" and multiple spaces are ignored unless between <pre>..</pre> tags or in a <textarea>)

Share this post


Link to post
Share on other sites
1 hour ago, Barand said:

You need "<br>" for newlines in an html document ("\n" and multiple spaces are ignored unless between <pre>..</pre> tags or in a <textarea>)

when i use <br/> it echos that exactly.

A new event<br/>Chelsea's Event

Share this post


Link to post
Share on other sites

try the html attribute instead of the text attribute

modal.find('#active-sheets').html(activesheets)

 

  • Great Answer 1

Share this post


Link to post
Share on other sites
1 minute ago, Barand said:

try the html attribute instead of the text attribute


modal.find('#active-sheets').html(activesheets)

 

Thats the one!!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.