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/
Related
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 last year.
This post was edited and submitted for review last year and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I am using an script which uses a remote file.css. I want to add a local file.css in order to override some remote.css styles.
Any suggestion of how could I do it?
Thank you!
If you just want to use the new styles instead, you can find the link element and just replace the href with the path to the other file. Like this:
document.querySelector("link[href=style.css]").href = "path/to/new/file.css";
If you want to override some styles, you'll need to make sure the new file is loaded after the first and then either use more specific selecors or !important. You can't really "edit" the file in the browser before loading it though, which is what it sounds like you might be asking about.
If you want to edit the css and not to replace all the css, you can use inline style or you can use bootstrap.
For example:
…
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 2 years ago.
Improve this question
I want to create an input space like the compose question input space of stackoverflow.
I have a blog. In the admin section of my blog I have a compose section. Now it only supports text and 1 paragraph. I want it to have the options to bold the text and make it italics or include some images by the user and also the support of multiple paras.
You can see a very good example of what I am trying to say in the stackoverflow's ask question section. The code should be in vanilla html, css and, js not react or any other framework.
I was not able to find anything over internet related to it.
Any help will be appreciated.
you can use a contenteditable element, see more at https://www.w3schools.com/tags/att_global_contenteditable.asp
You can use ctrl+b, ctrl+u, ctrl+i, etc. to make it bold, underlined, and italicised. You can also use document.execCommand() (https://www.w3schools.com/jsref/met_document_execcommand.asp) to create buttons that do this. document.execCommand() can change any CSS, so you can change size, color, bold, etc.
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 5 years ago.
Improve this question
I have plain HTML code, without Javascript code in it.
How would you detect if any form of Javascript was injected in the HTML ?
The application generates HTML client side. And needs to validate it once it arrives on the server.
The goal is NOT to remove Javascript, but simply detect the presence of it.
This is what tools like HTML Purifier are for. They break the input into tokens are run them against a white list.
This is safer than trying to find specific ways of inserting scripts into HTML, because there are tricks with malformed tags or non obvious attributes being used. See the XSS Evasion Cheat Sheet for example.
Removing can be easier than detecting - just escape all the HTML etc. you get with htmlspecialchars($string).
Alright, so this is a very interesting challenge:
First, check for all script tags, both capital and lowercase
<SCRIPT> <script> <sCrIPt>
Then, check for event handlers (onclick etc).
For this, we use DOM
$dom = new DOMDocument;
$dom->loadHTML($string);
You can work all sorts of magic with DOM, I recommend reading their documentation. Check for any attributes with "on" in them
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
green fisher here again.
Here is my this time question:
can we use CSS file in javascript?
I indeed know how to do the that: object.style = "";
however, if we can like do something really easy like: import stylesheet.css
then we can do something like object.style = stylesheet.getStyleById('#something')
well, those syntax above are all bullshit by my imagination, however, is there some similar way to do it?
The more appropriate approach would be to add class names to your elements. Then use a regular CSS file to style per class name.
Include in a normal CSS file
.red-text {
color: red;
}
Then add the relevant class name with JavaScript
document.getElementById("element").className += " red-text";
I think an easier way to do this is dynamically adding/removing classes/ids on the elements you want to style. You can do it using the jQuery addClass and removeClass functions, or with the element.className attribute.
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 mean i wanna iterate manually using a for-loop or something. but this piece of code i came up with seems to be not working. i like combining javascript with jquery since jquery is not my cup of tea for major projects. i don't know much jquery either, i would say I'm beginning to learn, though. how do you iterate over a nodelist in jquery is the question i have for all those jquery fans this time. is it similar to the javascript way? anyway this is what i have come up with (the code of a beginner).
$("sn"[i]).fadeIn();
$("sn"[i]) the part which failed, according to google chrome.
try this:
$("sn[" + i + "]").fadeIn();
I think you mean that "sn" is the selector for the nodes, in that case:
$("sn").fadeIn();
This works on all the elements that match the selector, jQuery will do the iteration. However if you want to select all elements that have the 'sn' class you should prefix the selector with a . like so: ".sn"
if you want to loop manually try:
$(".sn").each(function(i) {
$(this) // do some magic with the individual element here
});
See more on iterating with each here:
https://api.jquery.com/each/
Assuming sn is a variable containing the node list, you are probably looking for
$(sn[i])
or
sn.eq(i)
if sn is already a jQuery object.