Find a gibberish text within body using javascript [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to find a gibberish text that appears in the body without any HTML tags wrapping it. The source of this text is unknown. Not sure which approach would be better to find and remove it of the page Javascript
example:
<body>
<div>section</div>
Qui3Er3^6k
</body>
I am trying to find the string Qui3Er3^6k using javascript and remove it off the dom.
Note: I am not using jQuery, would like to achieve it with Javascript

If you're looking to remove Qui3Er3^6k from the DOM, you can use String.prototype.replaceAll():
document.body.innerHTML = document.body.innerHTML.replaceAll("Qui3Er3^6k", "");
<body>
<div>section</div>
Qui3Er3^6k
</body>

Related

How to call a he.js function to decode a JSON output element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have included the he.js file before my closing </body> tag.
But I need to call a function to have it decode my JSON output for the <figcaption> in a lightbox gallery.
How would I do this? I've tried the following but really not sure what I'm doing.
<script>
function(he)
{
root.he = he;
});
</script>
Apologies for the noob question...
This is the website in question
Once he.js included, you just need to use the he variable.
<script src="he.js"></script>
<script>
(function() {
console.log(he.version);
})();
</script>

Jquery selector on a variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to use jQuery to select attributes and elements of some html code, alter them with jQuery, and then append that edited html code in the DOM.
I want to achieve something like this:
var codeExample = $(".stuff").html();
$(codeExample).attr("id").val("2412");
$(codeExample).find("div #foo").attr("rel").val("bar");
$("#element").append(codeExample);
Is that possible? Or I first have to insert the html code in the DOM, and then find it with jQuery and edit it?
var codeExample = $(".stuff");
codeExample.attr("id", "2412");
codeExample.find("div#foo").attr("rel", "bar");
Though your id and rel are already modified. But if you still want to append it to #element do the following:
$("#element").append(codeExample);
As Rory states in the comment, your code will work and should have no problems, but as you want to replace the content already placed in DOM, it might be useful to use $('.stuff').replaceWith(codeExample); instead.
You can find more about replaceWith() in the jQuery documentation page.

Javascript: Replace Text in an Element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been working now for a while on the javascript process and can't really figure out on how to do this. I know how to basically tell javascript to set a certain value for a specific ID. But my Problem here is:
I'd like to write javascript to read out information (Server based, but that I'll do by myself ofc.) set it as var and then write it into text. It should look like this in the end:
Before writing (Without Javascript):
<h1 id="name" class="normal">Welcome, %Name%! What do you wish to do?</h1>
After writing (With Javascript):
<h1 id="name" class="normal">Welcome, John Connor! What do you wish to do?</h1>
So basically what I thought of is, that JS reads out information from server, then finds the h1 ID, searches in that text the %Name% value, and replaces it with the found name.
Please help me out here.Thanks!
Best Regards
Kodaigan
If using jQuery:
$('#name').html(function(index, html){
return html.replace('%Name%', yourVariable);
});
Pure javascript:
document.getElementById('name').innerHTML = document.getElementById('name').innerHTML.replace('%Name%','John');
This will replace a given string inside your h1 element.
If you have many paramaters, is better to use one of js lib's with templating.I prefere to use underscore.
http://underscorejs.org/#template. Also you can use if statements in youe template
How to use if statements in underscore.js templates?

PHP: Detect if string contains JavaScript/jQuery code inside and delete that part of code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a variable in PHP which contains different HTML code. Sometimes i find in this HTML code parts of javascript code or jquery code. This extra code may or may not have the <script> tag. So for example i might find jquery functions surrounded in a <p> tag.
Is there a way to detect this javascript/jquery code in the string and delete?
Yes, you can use HTMLPurifier to scrub bad code out of user input.
http://htmlpurifier.org/

How to make a JS that put html code on a page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i want to make a .js file that will store it seft some html tables and put the contents on the page that include .js file
how i can do that? this could replace some iframes roles.
Are you looking for innerHTML tag of Javascript.
Like this:-
document.getElementById('id').innerHTML = '<ol><li>html data</li></ol>';
You mean this?
document.body.innerHTML = '<p>Some html code</p>';

Categories

Resources