How and When can I use &lt or &gt? [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 7 years ago.
Improve this question
I'm fairly new to Javascript, and just now learned about &lt and &gt. I don't how to use them or how they would look like in javascript. Can you give me an example? And is it better to use it than < or >?

< and > are HTML representations of the < and > characters. You should use them when creating HTML where you want these characters to appear. Otherwise, they are interpreted as syntactic elements by the HTML engine.

Suppose you have to dynamically create a text box in JavaScript and the contents of the textbox include something like "Do not forget to use <diamond brackets> in your HashMap declaration", i.e. any string that contains an opening or closing diamond (aka angle) bracket. Then here you will have to use < and >, else the browser will parse them as HTML tags and produce an erroneous page.

Related

Finding file name with variables in between [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 3 months ago.
Improve this question
Having a hard time with Regex.
What would be the regex for finding a file name with variable in between them?
For eg:
File name : DON_2010_JOE_1222022.txt
In the above file name the words DON, JOE and the format .txt will remain constant. Rest numbers might change for every file. There could be characters as well instead of numbers in those two places.
What im looking for is basically something like DON_*_JOE_*.txt with * being whatever it could be.
Can someone please help me with this?
I tried DON_*_JOE_*.txt and obviously it did not work.
DON_(?<firstString>.*)_JOE_(?<secondString>.*).txt
You can use this. To access the specific group, you can use matcher.group("firstString").
In JavaScript:
"DON_2010_JOE_1222022.txt".match(/DON_.+_JOE_.+\.txt/)
whatever it could be
It is .+ except new lines.

why ` is different than ' in JavaScript? [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 3 years ago.
Improve this question
I started learning JavaScript, and I have faced this problem with strings.
the problem is
and the result is
Why are the results different?
`` - this is 'backtick' - when you use those characters, this is template string. This syntax allows you, to use for example, multiline strings or nested js variables ${}.
'' or "" - this is standard js syntax for strings, you cannot use here ${}

Prevent automatic HTML special character encoding [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 am working on a signature creator where you have some input fields and it generates an html page which you can use in Outlook as a signature. The problem is when there are special characters in 1 of the input fields, it will display some random characters ( e.g. é becomes é ). I've got some code to encode the special characters to html safe characters, but these get automatically converted back when injected in the html page. Is there a way to get the encoded characters into the html?
Here's jsfiddle of my problem (Open console in browser to view results):
https://jsfiddle.net/hdywwwf4/
This is what I want:
<h2 id="tester">ééé</h2>
This is what I get:
<h2 id="tester">ééé</h2>
Try using .innerText() to set the h2 content instead of .innerHTML()
This results in following element:
<h2 id="tester">&eacute;&eacute;&eacute; </h2>
https://jsfiddle.net/hdywwwf4/3/

Only if contains >< /!a-zA-Z or some of them with regular expression [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 7 years ago.
Improve this question
I need to check string if contains >< /!a-zA-Z or some of them (Also contains space). The only thing I know is a-zA-Z i need an example in C# or Javascript.
Use a "character class".
/[>< \/!a-zA-Z]/
Note that I've escaped the forward slash, since we're using forward slashes as delimiters.

Adding a Maxlength attribute to HTML using jQuery [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 8 years ago.
Improve this question
I'm having an issue at work with a rather picky client.
We use a rather strange script to deal with something that they require. We're an online assessment company and this script in general applies in our test player, rather than in our question editor, so we can't make change in the html, as you normally would with a text input box.
I know the maxlength attribute can be added through use of jQuery by using something along the lines of
$("input").prop("maxLength", 3)
However, I do not know how I would reference this in the HTML, as it would only be used in a couple of questions that use this script so making it standard for these questions by adding it to the JavaScript used is not an option.
The inputs that you need to apply this to would need to have ID's or Classes.
As you cannot edit the HTML this would only work, if those input's had ID's or Classes already.
If you want to apply it to an element with an Id you would do:
$("#IDGOESHERE").prop("maxLength", 3);
http://api.jquery.com/id-selector/
If it was with a class :
$(".CLASSNAMEHERE").prop("maxLength", 3);
http://api.jquery.com/class-selector/
You could get a little more fancy, by using EQ,
$("input").eq(5).prop("maxLength", 3);
Which would apply the max length to the 5th input on the page.
http://api.jquery.com/eq/

Categories