Expression language in javascript - javascript

I'm just wondering if it is possible to include Expression Language to a jQuery?I did try coding in jQuery like this: $('#{data.data}').val(); and it seems work but I want to know if it is really possible because in this question the EL for him doesn't work.
So i really want to know the cases if it is really possible or there are some cases or settings for you to be able use EL in jQuery.

I think #Balus answered this question in the link that you gave. As long you are using greater than or equals to servlet 2.4

Related

How works the getElementById(str) function (not to know how use it, and yes how are the function steps)?

I'd would like to know how is the getElementById(str) function steps on javascript.
I want to do a function based on it to get elements by a different way.
Okay, I just want to know the right way how may the function be created.
I already did think that it may use substr() to get some element in body, but will the substr() be the right way?
Then I'd just like to know about that, what the function do to get the element and its values.
getElementById() is a low-level DOM function, and asking "how it works" is asking the wrong question because that's dependent on the DOM / JS implementation.
It sounds to me what you're trying to do was already solved by several very popular JS libraries, namely jQuery. I suggest you start looking into jQuery's DOM selectors. If you really want to learn, look at how jQuery does it.

jquery nested selector or .find()

I wan to optomize a jquery code snippet. I intened to select a find a child element.I know how to do this by checking the length which can be acheived by two ways.
$("#parentElement #childElement").length
or
$("#parentElement").find("#childElement").length
Both of them will return 1 or 0 depeneding when wether the child exist or not.But Can you please suggest which is more optimized,faster & better in terms of coding standard.
It's extremely unlikely that this operation is causing a real-world performance problem. But answering the question asked:
By far, the fastest way to do that with jQuery is
if ($("#childElement").length)
...unless you really want to ignore the childElement if it's not inside parentElement. That's the only difference between your examples and the above.
Even faster without jQuery:
if (document.getElementById("childElement"))
not, again, that it's likely to matter at all.
Can you please suggest which is more optimized,faster & better in terms of coding standard?
Find is faster. You can read more about this here:
Learn optimize Jquery
From the documentation:
The .find() approach is faster because the first selection is handled without going through the Sizzle selector engine – ID-only selections are handled using document.getElementById(), which is extremely fast because it is native to the browser.

Tool to translate old javascript into jQuery

I know there are lots of tools on the net that can make our lives easier, for us, developers, including some that are quite powerful.
I ask if you know a tool to translate old javascript into jQuery?
A tool that can help make this stuff ? Because I have to translate thousands of lines of code in jQuery, and I think I have about 15 years... :)
Thanks !
No, such a tool doesn't exist. If it existed the code created by it wouldn't be something anyone wanted to work with.
The best way to start using jQuery is simply using jQuery for new stuff and if there's time slowly migrating old stuff manually - preferably stuff that's broken or needs modifications anyway.
The question doesn't make sense. jQuery is not a language that you can translate into. jQuery is a library that you can use in your Javascript code if you want. There is nothing jQuery can do that can't be done without it.
What you probably want is a tool to help you refactor your Javascript code, replacing specific patterns with equivalent jQuery methods. The problem is that this would produce a mess.
E.g. the jQuery equivalent to:
var x = document.getElementById('foo');
is:
var x = $('#foo');
but now x is a jQuery object, not a DOM object, so the code that uses it will break.
You could do:
var x = $('#foo')[0];
which would give you a DOM object, but then you are wasting jQuery.
One solution is to replace the code with:
var $x = $('#foo');
var x = $x[0];
Then stick to the convention that $var is the jQuery wrapped version of var. As refactoring progresses, you can use a tool that tells you 'x' is unused (like jsLint) to know that it's safe to remove it.
Various IDEs have tools to refactor Javascript a bit. See this question for some: How do you refactor JavaScript, HTML, CSS, etc?

making a text edit field

I am a beginner in HTML5, CSS3, and JavaScript. I reached my limit for the use of the trial version of Microsoft's OneNote. I like the program so much, I want to make an equivalent of it as an html version so I won't have to empty my pockets for the paid version.
The part I need help with is the part where you type in your notes. I don't know how to make a text edit field in html. Is it possible to do something like that? I would be satisfied if it could only do the same functions as note pad. Just so long as I am able to do the simple type and edit functions. Can someone show me how to code this or lead me to a site that teaches something like this?
Thanks! Tony.
There are plenty of solutions out there. Nicedit, CKEditor, etc. These all have a Rich text interface, and are javascript managed.
The simplest solution would be to just use a <textarea> which would allow for plain text input only.
The simplest way is to use the <textarea> tag in HTML. See this link too.
You can also use HTML5 Data caching to save your notes locally through your browser after implementing your textarea tags.
Here's a neat little plugin that should be relatively minor to install/use.
https://github.com/ekdevdes/storage.js

onclick or onClick?

I thought that binding the click event in javascript is done by using node.onclick, and Chrome/Firefox seem to agree with me, but I saw it written .onClick here 4 times by 3 people, so it can't be a typo and I doubt that it's a coincidence.
So, why are people writing onClick when it does not work?
UPDATE: There are two good explanations; I don't know which one of them is the most plausible, so I will accept the answer based on popular vote, tomorrow.
Because some browsers (depending on the DOCTYPE) are tolerant of the inline onClick="something();" attribute...it seems to have spread a bit, even into JavaScript questions where it doesn't work, since case matters.
Also, specifically to stackoverflow...people using it in questions...well, most of the time they wouldn't be asking a question if their code worked :)
#Nick Craver pretty much has it nailed down and has my vote; I just wanted to add my thought.
I think it's onClick is often used in conversation because it's a bit more readable, and as an old habit from those of us who predate all lowercase HTML. However, in code - both JavaScript and HTML, onclick is correct and the only way it should appear. Even if you're using an older HTML doctype, stick to lowercase. If you ever update to a more strict doctype, you'll be glad your code doesn't need to be checked for case.
It's just that for most browsers HTML attributes are case insensitive, but JS is case-sensitive. onClick will work in html, but if you're defining the handler in JS, you need to use the lowercased onclick.
In that specific question, I used "onClick" as the original question had it in that vein and I try to change as little of the OPs code as possible to make a solution, so that they can see their mistake easily.
The camel case is invalid technically, though I like camel case in general. Frankly, it always annoys me when I see that method, as I think "Where's jQuery!".
It is heavily prevalent in the world, I see it all the time in source.
I edited my answer on the referenced question to fit, thanks for pointing it out.

Categories