SearchRecent posts
The Random ToolboxDrupal 7 Setting up variables for use in a template (preprocess and process functions) Rendering Drupal 7 fields (the right way) Linux Secure Copy (scp) command Restrict Free Shipping in Magento Quickbooks Text Connection Ticket Cross-Site Request Forgery (CSRF) jQuery Events: MouseOver / MouseOut vs. MouseEnter / MouseLeave Monthly archive
|
Remove Newline from Text of Element / Convert \n to <br />I was trying to write an if statement to perform some actions when a certain error message was present. I went round and round trying to figure out why the text of the element wouldn't match in my if statement. Turns out it was because there was a line break before the text which is considered content. I stripped it out as you can see below: var msg = ""; var applied = "You have already applied for this position."; var msg = jQuery('.messages.status').text(); jQuery('.messages.status').text(''); msg = msg.replace(/\n/g,""); jQuery('.messages.status').text(msg); if(msg == "You have already applied for this position.") { // my actions here } And if you want to replace a newline with a break tag: string = string.replace(/\n/g,"<br />"); |