The $ is simply a variable that represents the jquery object. You could instead type
jquery(‘#para’).hide(); *see my note at bottom
but using the $ instead of jquery is much faster.
Notice the parenthesis that come after $
they contain the selector. In this case we are selecting the element that has the id of para. jQuery will then do something with that element. (An element is another way to say a tag.)
Once jQuery has selected the element it will do something to it. In this case we call the hide method to hide the element. It will disappear!
var para = document.getElementById(‘para’);
So last post I put up a link to a regex builder. What would you want to use a regular expression for? Regular expressions let you determine if a pattern of characters is a match. So you can test to see if a set of characters is numeric. A simple use for this would be to check to see if a telephone number typed into a form is a number and not letters. Or another way to say the same thing, is you can use a regular expression to check to see if input is valid.
In the example I just gave, the validation is primarily for the benefit of the user. We don’t want them to make a mistake when they type in the phone number, so we check it for them.
However input validation is a very important part of programming in general for security reasons. Anywhere there is input into a program, a text box on a web page for example, it is a place for someone to attack that system. In general, if there is no place to log in, there is no place to attempt to guess a password. However, user input is a critical part of computer applications.
Knowing that, we have to take precautions against malicious users who may try to use our inputs to inject harmful information such as foreign code into our system. One way to test input to make it is valid, is to use regular expressions as part of input validation.
Regular expressions are patterns that match strings of text. Joel Norris, @joelrnorris, tweets a useful site for learning regular expressions. The site is: Build it!
Check it out!
Speaking of Angular, I can go ahead and put this blog to work. I was interested to see if there was any critique of Angular on the web. I found one and it discussed the crossover between presentation languages and behavioral languages. It was interesting, but more interesting to me was that the author is in the process of creating an alternative to angular called jqcomponents and is based on jQuery. I want to give that a try. The link is here: jqcomponents