Classes, Properties, Methods and Ships Javascript is an object oriented (OO) programming language. Many object oriented programming languages, such as Java and ActionScript, are class based. A ‘class’ acts as a blueprint for objects or instances created from the blueprint. We may, for example, have a class ‘Ship’ that defines the basic characteristics of a…
Read MoreWith Javascript 1.6 we have some new ways to manipulate arrays. To check whether your favourite browser supports these consult this compatibility table. indexOf() and lastIndexOf() Avid readers will recognize indexOf() and lastIndexOf() from a previous post on string manipulation. These methods are now available for arrays and are used to search an array for…
Read MoreA Pop and Push and this land is ours With Javascript arrays there are a host of methods allowing us to manipulate the content. We’ll start with the ‘traditional’ array methods. pop() – to remove the last element Given an array of: We can pop() the last value with: … and that would be ‘Combat…
Read MoreA couple of useful ‘vanilla’ Javascript methods that are a little ignored although they have been around since DOM2. The hasAttributes() Method This checks to see if an element has any attributes and a boolean value – true for yes indeedy and false for nope soz is returned. Take this HTML snippet: If we need…
Read MoreAs part of my occasional series on string manipulation in Javascript here I offer some tricks for working with URLs. You might also like Addressing the Problem – String Manipulation with Javascript or replaceAll(). Manipulating the URL of the page you are on To get the URL of the page you are currently on use:…
Read MoreThe Problem Although getting data from databases is obviously loads better than having to hard-code zillions of pages, one problem with dynamic data is that the data can varying enormously in quality and length. Take the example of an address. We may have: Hill top View, 54 Manor Walk, Chucklebury, Springfield, Yorkshire, S99 5TP or…
Read MoreEU law in its infinite wisdom now requires web sites to be explicit about Cookie usage. I am not going to explore the legal rights or wrongs of these regulations. If you want more information see: Information Commissioner’s Office Any EU web users will by now have seen these “cookie consent” forms pop up on…
Read MoreNote: There is a newer post that repeats the same functionality of this example but makes use of Knockout.js – Adding Form Fields Dynamically with Knockout.js Sometimes, for example with a content management system, the user needs the ability to add fields dynamically to a HTML form. As jQuery is the King of DOM then…
Read MoreAn accordion effect is a nice way to efficiently use the limited space available for menus. In this simple example the staring HTML is a nested <ul> list. The HTML is: The CSS for this is as follows: The key line here is the display:none set for the child <ul> elements. The jQuery is incredibly…
Read MoreBefore the fun begins – beware you’ll need to test this page with Chrome. This is one of those ‘pixie fairy magic’ features that get gifted to web developers from time to time. Speech input fields let you speak to the browser (yes the browser) and it will recognise what you say and enter it…
Read More