Skip to main content

CODING

jQuery - Key Pressed Events

In this tutorial we're providing example for determining which keyboard's key is pressed. Here is a part of HTML code we'll use for the example:

<input type="text" id="testbox" />

{mobile_block=responsive_ad_728_90}

The following jQuery code gets the event and shows the pressed key as a numerical code:

SilverStripe Syntax Highlighter

A blog dedicated to software design and development, as our company blog is, usually has many articles that contain program code examples. It would be very useful to have code highlighting enabled by default in SilverStripe CMS.

However, we can add it easyily. One of the most used JavaScript tool fo code highlighting is SyntaxHighligher created by Alex Gorbatchev (http://alexgorbatchev.com). We're going to describe the procedure for implementing SyntaxHiglighter to SilverStripe CMS in step-by-step tutorial.

{mobile_block=responsive_ad_728_90}

jQuery - Read More.../Read Less... Link

One of very usefull tip is for creating a "Read More..." link when only a few lines of text are displayed and the rest of the text is shown after clicking the link.

<div>
    Short text
</div>
<span class="readmorelink">Read More...</span>
<div class="readmoretext">
    Here is more text.
</div>

{mobile_block=responsive_ad_2_300_250}

Here is jQuery code for displaying rest of the text when Read More link is clicked:

jQuery - Element Get/Lost Focus

There are two important jQuery functions for dealing with element's focus. They are:

.focus(handler) - to set focus to a field
.blur(handler) - to get focus from a field

{mobile_block=responsive_ad_2_300_250}

A part of HTML page:

jQuery - Change CSS Style

As you can see in our previous articles for jQuery tips and tricks, this Javascript library can finish almost all we want to do.

We can get DOM nodes, access and change their values, create or remove elements on the fly... And now we'll provide a simple way for changing CSS style of an element.

{mobile_block=responsive_ad_2_300_250}

Like in our other examples, here is a part of HTML file that will serve to our goal: