This question already has answers here:
Strip HTML from Text JavaScript
(44 answers)
jQuery (almost) equivalent of PHP's strip_tags()
(9 answers)
Closed 8 years ago.
How to remove <p> and </p> from a text in javascript?
I have a string
<p> This is a text</p>
and I want to remove the <p> and the </p>.
How can I do that in Javascript?
Use the replace() function.
For example: "<p> This is a text</p>".replace(/<\/?p>/g,"").
Related
This question already has answers here:
Can scripts be inserted with innerHTML?
(26 answers)
script tag create with innerHTML of a div doesn't work
(3 answers)
Closed 3 years ago.
I will make javascript inside javascript like this code.
<p id="div"></p>
<p id="jancuk"></p>
<script>
document.getElementById("jancuk").innerHTML = '<script
src="encryption.js" type="text/javascript">' + '</script>';
</script>
<script>
document.getElementById("div").innerHTML = "text show"; </script>
Code can't work correctly.
I will include data javascript 1 to javascript 2. it's mean wrapper inside one html document.
Please help me if you know about this.
This question already has answers here:
How to prevent XSS with HTML/PHP?
(9 answers)
Closed 3 years ago.
Probably this is a known problem and there is a specific best practice.
I have to fill a text field value with received text from backend.
I this text contains some 'special characters' (for example " <) I have some issued during the rendering of the page.
How can I solve this?
Can I solve this issue front-end side?
I can use only javascript front-end side. I not use PHP;
I use this html code:
<input class="myclass" value="<%= text_from-backend %>" placeholder="My Placeholder"/>
You can replace special characters in PHP:
<input class="myclass" value="preg_replace('/[^ a-z\d]/ui','','<%= text_from-backend %>');" placeholder="My Placeholder"/>
This question already has answers here:
Is "clear" a reserved word in Javascript?
(4 answers)
Why can't I call a function named clear from an onclick attribute?
(3 answers)
How to clear a textbox using javascript
(15 answers)
Closed 4 years ago.
I only know how to use Javascript and HTML5
I have tried so many ways to clear textarea but they won't work
<textarea id="texti" placeholder="Place Text Here Or Paste Text"></textarea>
<button class="button" type="button" onclick="clear()">CLEAR</button>
<script type="text/javascript">
function clear(){
document.getElementById("texti").innerHTML= "";
}
</script>
in the function part I have tried
document.getElementById("texti").value=0;
document.getElementById("texti").value="";
but apparently none of theme works in my code
End your textarea tag
Use .value
Do NOT use reserved words like clear
function clearIt() {
document.getElementById("texti").value = "";
}
<textarea id="texti" placeholder="Place Text Here Or Paste Text">XXX</textarea>
<button class="button" type="button" onclick="clearIt()">CLEAR</button>
This question already has answers here:
Need to escape a special character in a jQuery selector string
(7 answers)
Closed 4 years ago.
I'm trying to select an element this way
$('#QR~QID345')
because the element's id is QR~QID345 but the selector doesn't work with ~, is there any fix?
Changing the id is not an option in this case.
You can escape ~ with \\
alert( $('#QR\\~QID345').text() );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="QR~QID345">Hello</div>
You can use $.escapeSelector to escapes any character that has a special meaning in a CSS selector.
var id = $.escapeSelector("QR~QID345");
console.log($('#' + id).text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="QR~QID345">
Hello World
</p>
As been noted by Rory McCrossan on the comment, $.escapeSelector was added on version 3.0
Doc: $.escapeSelector()
This question already has answers here:
Executing <script> injected by innerHTML after AJAX call
(12 answers)
Closed 8 years ago.
I have an ajax response which returns html and javascript as follows:
<div class="contents">
<div>1</div>
<script>
var test = "test";
</script>
</div>
How can I access the variable test?
Append the response in some temp div, get the value from variable and remove the div.
$("<div id='dvTemp'></div>").html(AjaxResponse).appendTo("body");
alert(test);
$("#dvTemp").remove();