PHP has a function called nl2br() which takes all the newlines in a
string and turns them into break tags <br>. I need to do the same in
javascript. Is this about right? I'm not sure how one is supposed to
reference invisible characters in Javascript strings. I took an example
on the web and tried to modify it to my uses.
function nl2br_js(myString) {
var regX = /
/gi ;
s = new String(myString);
s = s.replace(regX, "<br />
");
return s;
}
After looking around quite a bit using Google, I still couldn't find
out what the gi in the above example is for. What is it?
I have the following Javascript code to write a code to the page using InnerHTML. But instead of writing the code, it shows the content of the iframe. How can I make the code write straight text of the HTML code...
I am trying to replace new line character with the <br /> tags. The following two javascript functions that I've found, work in Firefox but do not work in Internet Explorer (I have version 7 installed on my machine).
I need to replace custom tags to spans. I have: Code: <block style="color:blue" class="block01" limit="100">This is a block</block> I need to fetch the attributes and add them to a span, like: Code: <span style="color:blue" class="block01" limit="100">This is a block</span> There's a few on the page so I need to change all of them some may have many attributes.
I am trying to replace all newline characters with <br /> tags. The following two javascript functions that I've found, work in Firefox but do not work in Internet Explorer (I have version 7 installed on my machine).
When trying to emulate php's nl2br() function in javascript, I ran into something quite disturbing.
Code: cms.t.value = cms.t.value.replace(/ /gi, '<br /> '); Using this piece of code, I was really surprised that the newlines weren't preceded by <br />, but by <br>. I really don't understand why that would happen. Why can't I decide my own replacement string? .
in the code below I an trying to replace a string with another string, then write the new string in JavaScript tags. But the result is not what I wanted: first the original string was not replaced, second plain text is shown, instead of popping up an alert. Is there a way I can replace the string and execute the command?
On my site I use an SVG image. The <embed> tag works fine in Opera and Firefox. And <img> works fine in Chrome and Safari. I would like to know if it is possible to change the tag with an 'if' browser statement, and if it is ho would I write it.
if (jQuery.browser.webkit) { * // Replace <embed> with <img> }
I have some Javascript code that reads and sometimes sets the content of a textarea. I want this to be reasonably browser and platform independent. My question is, what characters should I expect to find at the end of a line? I suspect that I need to cope with either "" or""; can someone confirm?
Setting the content is more of a challenge. I don't want to have nasty browser detection to select what to use for newlines. Is there one newline pattern that is safe for all browsers?
I've written this javascript that puts lines of text into a readonly textarea, each line ends with a newline character. I have a function that checks that no duplicates exist, it does this by splitting the textarea by newlines into an array. This works as it should in Firefox, but not in IE. Code:
I dynamically make a textarea and save the text, but when I try to output it with javascript, the newlines screw it up... if you don't understand what i mean, here is some code:
Code:
With that newline in javascript, the javascript throws an error. i am working in jsp, so how would i change the text that is put into the textarea with javascript without changing the newlines?
Can't seem to make it work, I have seen many examples but they are all just for 1 div tag. When i trymore than one it doesn't work anymore.The first one works, if i have more than 1 then the other don't work.
using the following jquery $(document).ready(function(){ $("#toggle-text").click(function () { var divvalue= this.value;
Is it possible to trigger the action of a form with a submit button that's outside the form tags? If so, how should this example be rescripted to make the input tag work outside the form tags?
I really know nothing about how to code JavaScript (I know what it is and what it does) and I need a script to go in the head of my page and look for all <a> tags that have <img> tags inside of them and add a rel="lightbox" attribute to them.
<script type="text/javascript"> var str="Welcome to Microsoft! Microsoft Microsoft"; var stringToBeFound = 'Microsoft' var ReplaceString = 'site' document.write(str.replace(stringToBeFound , ReplaceString )); </script>
My problem is im trying to use string.replace that is not case sensitive and replace every string found. I could use regular expression with it but my stringToBeFound is a dynamic variable im getting it from my database
i am trying to make an online graphing calculator with javascript. dont ask how because i dont know. but there is an annoying error in a do...while loop. although it should break out of the loop when the |'s (absolute value signs) are replaced with Math.abs( and ). here is the code.
I ran into a problem that I could not fix myself, I am trying to replace a string with another string, the replace lines look like this:
Code: var word = document.getElementById("word").innerHTML; document.getElementById("word").innerHTML = wordd.replace(/B/g, '<span class="style106">B</span><span class="style107"> </span>'); It works just perfectly if left alone, but I need to replace every letter inside this string, adding those style and span tags around each and every letter. So if I add another line to this code, like this:
I have a web form that needs to be printed for signatures. Problem is the form is just a bit too big and always prints on two pages. Is there a meta tag that will tell the printer to print the document on one page...or is there a meta tag I can use to print at 80%?
I have a div which includes many others tags (a, input, any others links). How can I disable the whole div? I want to any of the included tags may not be enable.
I have some extensive animation going on in this script. I have all the behavior I want out of this script. A 3D carousel interface, each window in the carousel is a separate UI window. It uses active scrolling for navs and content...like (iphone).The problem is that I have optimized to my best and still cant gain any performance out of IE. It runs pretty fast in FF, and in Safari. I have reversed loops, I have vared all my Math, I have stripped equations, could do more I guess, and I have made attempts at preventing even bubbling. I have minimized the use of <img> tags as well. I have even cached most methods and use a constructor method to create new HTML elements.At this point I am starting to feel like I am getting into techniques and areas of JS I just don't understand well.Here is example of a method I would like to optimize:
this.anim = function () { var s = Math.sin(s3D.A * .01); var c = Math.cos(s3D.A * .01);[code]....
I'm tryng to make two boxes on my page always the same hight, no matter how much text is inside one of them.
So the boxes will always be the hight of the box with the most text.
you can see what I meen here:
[URL]
I would wan't the two boxes to be the hight of the one to the left with the most text.
At first I thought it could be done in css, but I was told that I needed javascript to do it. And I don't have so much experience with javascript, but I can try
what I'm trying to do is get text from between two tags, just like the title says. Now I know I can get that through the innerHTML property, but its just that, I don't want HTML, I want plain text. Consider the following example.
<span id="p-5641"> This is <strong>strong</strong> & you should really put <em>emphasis</em> on that <a href="#">anchor</a>.<br>Line broken </span>
Now, what I want is, to get the text from between these span tags. That can be done by refering the ID of the span & innerHTML but that would give HTML & I want to strip off the HTML from it, so that I'm left with plain text, like
This is strong & you should really put emphasis on that anchor. Line broken with <br> & <p> tags preserved.