Pure CSS3 LavaLamp Menu


https://dzone.com/articles/pure-css3-lavalamp-menu

https://www.script-tutorials.com/demos/249/index.html

Advertisements

Changing placeholder text when window resizes with jQuery

Tags


<input type="text" placeholder="Search Microsoft Partner Network" class="my_textarea'">

Placeholder : Search Microsoft Partner Network

Using below code changing the resolution 680 below screen size:

Output :

Placeholder : Reply...

$('.my_textarea').each(function() { $(this).data('placeholder', $(this).attr('placeholder')); }); function changePlaceholder() { if( $(window).width() < 680 ){ $('.my_textarea').attr('placeholder','Reply...'); } else { $('.my_textarea').each(function() { $(this).attr('placeholder', $(this).data('placeholder'));

});

}

}

$(window).resize( changePlaceholder ).trigger('resize');

How do I auto-hide placeholder text upon focus using css or jquery?

Tags


Using CSS:

<input type="text" placeholder="enter your text" />
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* FF 4-18 */
input:focus::-moz-placeholder { color:transparent; } /* FF 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* IE 10+ */

Using JQuery:

<input id ="myID" type="text" placeholder="enter your text " />
$(function () {

    $('#myId').data('holder', $('#myId').attr('placeholder'));

    $('#myId').focusin(function () {
        $(this).attr('placeholder', '');
    });
    $('#myId').focusout(function () {
        $(this).attr('placeholder', $(this).data('holder'));
    });


});

Affiliate Marketing In India : What, Why and How


Have you heard about Affiliate marketing? If you have and are just starting out being an affiliate in India, this post will give you a complete overview of affiliate marketing landscape in India.

Affiliate Marketing

But first, let us understand what is Affiliate Marketing – The business of marketing third party products on your website, and being recompensed for each purchase, sale, click or revenue generated by visitors who have reached the Seller through your advertisements, vouchers or other incentives on your website, is generally known as ‘Affiliate Marketing’.

Who Offers Affiliate Marketing in India?

Since it is a low risk and high reward marketing and sales strategy, Affiliate Marketing has found many takers in India. These can be broadly divided into two categories – ‘Affiliate Networks’ and ‘Affiliate Marketers’ or ‘Publishers’. Some of the entities functioning as an Affiliate Networks in the Indian market are:

Some of the Affiliate Marketers or Publishers prominent in India are as under:

How is Affiliate Marketing done?

Merchants assign a fixed commission to the ‘link’ or ‘banner’ of the products that they offer online. The affiliates understand the terms they are offered and publish the link or banner on their website, blog etc. and the link tracks all the traffic and sales generated through each affiliate as the link/ URL given to each affiliate is unique.

1.) Affiliate Networks offer services for facilitating affiliate marketing. They provide a network for ‘Advertisers’ / merchants as well as ‘Publishers’ / marketers.

Below are the different ways they function:

      • When a customer clicks on the link available on an affiliate’s website, a cookie is set on the visitor’s browser that identifies the advertiser, the publisher, and the specific link and payment rates. When the visitor makes an actual purchase online or fills out a form, that transaction is tracked and recorded by concerned network. After recording the transaction, it handles all of the collection and processing required to ensure fair and timely commission payment for the publisher, and all of the administration and verification necessary to ensure quality sales and leads for the advertiser.

Here the cookie is active for 30 days, therefore in the event that the visitor goes to the merchant’s website within 30 days of first activating the cookie, the affiliate will get paid for any sale (and multiple sales) occurring within those 30 days.

      • Some affiliate networks use a combination of html ‘end of sale’ code (which is placed in your shopping cart or on your ‘order confirmation’/’thank you’ page) and cookies (which are created on the customers PC after they click on one of your advertisements) to track sales. This ‘two key’ combination ensures that network will ONLY track the sales that are sent to you from that network’s affiliates. Cookies are deleted once a transaction occurs or typically expire within ninety days. The life of the cookie can be set to 45, 60, 90, 120, 150 days, 1 year, 2 year or indefinitely.

Affiliate marketers or Publishers operate in the following manner:

      • Sites like CouponzGuru, Pennyful, CouponsDuniya and Cashkaro, as the same suggests, provide coupons to customers and cash back options that may be used while making a purchase on any merchant site, having reached the said merchant site after perusing and clicking on the relevant coupon/ offer at the above-noted affiliate websites.
      • There are others like Groupon and mydala which offer coupons and discounts at offline entities like restaurants, gyms, grocery stores, health and beauty stores in addition to the online deals at ecommerce merchant sites.

2.) Ecommerce portals in India are offering their own affiliate programs also, such as Flipkart, Jabong, Snapdeal Amazon Associates and so on offer their respective affiliates up to 15% for each successful referral (which ends in purchase). Websites can place banners or links re-directing visitors to products on these sites.

The criterion for payment of commission to affiliates is usually as under

  • CPM or ‘Cost per 1000 impressions’ – This is the value paid by the merchant to the affiliate for every 1000 page views of text, banner, images.
  • CPS or ‘Cost per sale’ – This is the amount paid by the merchant to the affiliate on an actual purchase/ transaction made by the visitor.
  • CPL or ‘Cost per lead’ – The amount paid by the merchant to the affiliate when a visitor leaves personal information such as name, email ID etc., allowing the merchant to get in touch with such visitor.
  • CPC or ‘Cost per click’ – The value paid by the merchant to the affiliate for each click on the advertisement, text, banner.
  • CPA or ‘Cost per acquisition’ – The value paid by the merchant for an action, such as filing up a form, signing up for something etc.

What are its Drawbacks

Although not probable, but suffering at the hands of Affiliate marketing is always a possibility. Certain issues that may crop up while engaging in affiliate marketing are:

  • Affiliates can indulge in misleading the number of visitors / clicks etc. in an attempt to get higher commissions from merchants.
  • An Affiliate may offer discounts and offers on a product or service which is entirely untrue or exaggerated to the extent of being impossible to deliver, which may lead to loss of customers for the merchant.
  • Merchants may promise high commission in the beginning, only to reduce the commission rates or percentages with time.
  • Link hijackers may hijack affiliate links and direct the payment of commission to themselves.
  • Merchants may suffer a gradual decline in profits, as consumers who would have visited their website directly may only now shop/ purview their products through the affiliate’s website, meaning thereby that what would have been a direct sale, becomes a sale for which the merchant will now have to pay a commission.

Scope in India?

Although it may be at its nascent stages in India, the advantages of affiliate marketing, its low cost and high benefit for both merchants and affiliates, the slowly growing number of service providers offering their expertise for setting up affiliate marketing programs, software and network, increase in internet penetration in India, the growing craze and convenience of ecommerce companies – all factors go to show that Affiliate Marketing (when embarked upon after carrying out due diligence by both merchants and affiliates) will only earn more beneficiaries with the time to come.

Author’s View

Affiliate Marketing is the most cost effective and viral channel of marketing for E-Commerce companies. They just pay for the transactions that the affiliates brings, unlike other channels where they need to pay for each view or click irrespective of the transactions.

Above all, advertisers indirectly get a lot of exposure to the affiliate’s marketing activities at various channels as affiliates pushing the advertiser’s content to generate more sales. Also each affiliate has his / her own set of ideas and thus I call affiliate marketing as one most effective “crowd” sourced method of marketing.

structure a Sass project


One of the most useful features of Sass is being able to separate your stylesheets into separate files. You can then use the @import directive to include the source of your individual files into one master stylesheet.

But how should you structure your Sass projects? Is there a standard way of separating out your CSS files?

Basic directory structure

I like to layout my Sass projects like this:

stylesheets/
|
|-- modules/              # Common modules
|   |-- _all.scss         # Include to get all modules
|   |-- _utility.scss     # Module name
|   |-- _colors.scss      # Etc...
|   ...
|
|-- partials/             # Partials
|   |-- _base.sass        # imports for all mixins + global project variables
|   |-- _buttons.scss     # buttons
|   |-- _figures.scss     # figures
|   |-- _grids.scss       # grids
|   |-- _typography.scss  # typography
|   |-- _reset.scss       # reset
|   ...
|
|-- vendor/               # CSS or Sass from other projects
|   |-- _colorpicker.scss
|   |-- _jquery.ui.core.scss
|   ...
|
`-- main.scss            # primary Sass file

Primary stylesheet

This allows me to keep my primary Sass file extremely clean:

// Modules and Variables
@import "partials/base";

// Partials
@import "partials/reset";
@import "partials/typography";
@import "partials/buttons";
@import "partials/figures";
@import "partials/grids";
// ...

// Third-party
@import "vendor/colorpicker";
@import "vendor/jquery.ui.core";

Modules, partials, and vendor

As you can see this divides my project into three basic types of files. Modules, partials, and vendored stylesheets.

  • The modules directory is reserved for Sass code that doesn’t cause Sass to actually output CSS. Things like mixin declarations, functions, and variables.
  • The partials directory is where the meat of my CSS is constructed. A lot of folks like to break their stylesheets into header, content, sidebar, and footer components (and a few others). As I’m more of a SMACSS guy myself, I like to break things down into much finer categories (typography, buttons, textboxes, selectboxes, etc…).
  • The vendor directory is for third-party CSS. This is handy when using prepackaged components developed by other people (or for your own components that are maintained in another project). jQuery UI and a color picker are examples of CSS that you might want to place in the vendor directory. As a general rule I make it a point not to modify files in my vendor directory. If I need to make modifications I add those after the vendored files are included in my primary stylesheet. This should make it easy for me to update my third-party stylesheets to more current versions in the future.

Using a base partial

In my partials directory you will also notice that I have a base partial. The purpose of this partial is to load up my Sass environment so that it’s easy to construct a stylesheet.

It might look something like this:

// Use Compass ('cause it rocks!)
@import "compass";

// Font weights
$light: 100;
$regular: 400;
$bold: 600;

// Base Font
$base-font-family: sans-serif;
$base-font-weight: $regular;
$base-font-size: 13px;
$base-line-height: 1.4;

// Fixed Font
$fixed-font-family: monospace;
$fixed-font-size: 85%;
$fixed-line-height: $base-line-height;

// Headings
$header-font-weight: $bold;

@import "modules/all";

The base stylesheet sets a couple of global variables and loads up all of my Sass modules. Again modules are not allowed to contain anything that would cause CSS output when importing. Tying all of my variables and modules up into a base partial gives me access to my entire Sass environment whenever I’m setting up a new stylesheet with a single import statement. This allows me to build multiple stylesheets by importing different partials. Multiple stylesheets are handy once a project grows to a certain size.

One step further

At UserVoice we take this pattern one step further. Since we have multiple sub-projects all bundled together in a single Rails app, we bundle each sub-project into a separate top-level directory. Our stylesheet directory looks more like this:

stylesheets/
|
|-- admin/           # Admin sub-project
|   |-- modules/
|   |-- partials/
|   `-- _base.scss
|
|-- account/         # Account sub-project
|   |-- modules/
|   |-- partials/
|   `-- _base.scss
|
|-- site/            # Site sub-project
|   |-- modules/
|   |-- partials/
|   `-- _base.scss
|
|-- vendor/          # CSS or Sass from other projects
|   |-- _colorpicker-1.1.scss
|   |-- _jquery.ui.core-1.9.1.scss
|   ...
|
|-- admin.scss       # Primary stylesheets for each project
|-- account.scss
`-- site.scss

As you can see each sub-project has it’s own primary stylesheet, modules, partials, and base. Vendored stylesheets are typically versioned and have their own top-level directory. This is a handy pattern to use on very large Sass projects.

Learning SASS: A Beginner’s Guide to SASS

Tags

,


Writing a lot of CSS can be overwhelming that is why learning SASS and LESS can make  any web developer and designer’s life much easier. For a beginner, you might find it fine but as time goes by and your CSS skills are improving. You begin to wonder if there is a way so that you don’t need to repeat a lot of CSS codes in your style sheet. The good news is, there is one! Thanks to the CSS pre – processor, it’s now possible to write concise CSS codes without repeating each of them again and again. It is even formatted nicely. You can perform computations and do dynamic styling using these pre-processing methods. There are two pre-processing methods that I will tackle: SASS and LESS. For this tutorial I will talk about SASS first and then on a separate tutorial, I’ll talk about LESS.

CSS Drawbacks

Using CSS only might work for you but when making big websites with multiple pages, there might be some features you wish CSS has. Take a look at the following disadvantages of using CSS alone.

  • No way to re-use common style rules.
  • No way to specify variables that can be defined and re-used all through the style sheet.
  • You can’t execute computations where you can add numerical values to elements.

Advantages of Using Pre-Processing Methods

While using CSS alone might give you nuisance, using pre-processing methods can save you a lot of time and effort. Check out the list of advantages of using pre-processing methods below.

  • Allows you to use variables that can be re-used all throughout the style sheet.
  • Higher level style syntax that provides advanced CSS features.
  • Compiled CSS files are uploaded to the production web server.

What Is SASS?

SASS stands for Syntactically Awesome Style Sheets and was  designed and created by Hampton Catlin. SASS manipulates CSS using variables, mixins, inheritance and nesting rules. Given the extensions .sass and .scss respectively, it’s translated to well-formatted CSS using a command line tool or web-framework plugin.

SASS makes it easier to write less CSS codes and manipulate them dynamically. It’s a great way to write more functional CSS codes and can speed up the workflow of every web developer and designer.

.sass VS. .scss Format

Before we begin on how to use SASS, let’s compare .sass and .scss extensions of SASS. First I will provide a simple CSS code and then I will show you how to simplify them on both extensions of SASS.

CSS Code

For our CSS, I used a header tag and put a zero value for margin and padding then white color for its text color.

1
2
3
4
5
header {
     margin: 0;
     padding: 0;
     color: #fff;
}

.scss Extension Format (New Way of Writing SASS)

To format this into .scss extension format, we will use a variable $color and give it a hexadecimal color value of #fff for white color. And then under the CSS style, instead of putting a hexadecimal color value of #fff, use the variable $color that was set in the beginning of the code.

1
2
3
4
5
6
$color#fff;
header {
    margin: 0;
    padding:0;
    color: $color;
}

.sass Extension Format (Old Way of Writing SASS)

For our .sass extension, we will have the same variable and value just like the .scss extension format, but, this time, without semi-colons and brackets. Notice that indentions are more reliant. This is the old format in writing SASS.

1
2
3
4
5
$color: #fff
header
   margin: 0
   padding: 0
   color: $color

Resources you need to complete this tutorial:

Installing Ruby

Before you can be able to test how SASS works, you need to download Ruby to your computer. Launch the Ruby installer and you will be prompted with the Setup page. Select your preferred language and click OK.

1

Then click on I accept the License radio button. 2

Next, install it to your preferred location and make sure that the radio button for Add Ruby executables to your PATH is checked. Click the Install button. This will install the software and when it’s done installing, just click the Finish button.

34

Checking if Ruby is Running Properly

Now that you have installed Ruby, let’s go ahead and check if this is working properly. Open Command Prompt and type the word ruby -v. And you can see, it would return the current version of the Ruby installed along with the date. If it’s returning an error, it could be that Ruby was not installed correctly or you did not put the Ruby executable into your path.

5

Installing SASS

To install SASS, open Command Prompt and type the word gem install sass and you can see that the Installation Prompt that it was successfully installed.

6

Preparing the Necessary Files

Before digging in with SASS, we need to prepare the necessary file you need before you code. Create a new folder to your preferred location (for this tutorial, I placed mine on my desktop) and name it SASS or any name you preferred. Inside the SASS folder, create an HTML file and name it index.html. For the HTML content put the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
   
 <head>
        
<title>Introduction to SASS</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<header>
<h1>Sass Sample Document</h1>
<h2>A 1stwebdesigner tutorial</h2>
</header>
<div>
<p id="samplepara">Simple paragraph of text</p>
<p>Another paragraph of text</p>
</div>
<div>
<ul id="list1">
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
</ul>
</div>
<footer>
<h3>This is a cool footer content</h3>
</footer>
</div>
</body>
</html>

Now for our SASS file, create a new blank file in your text editor and name it style.scss. If you followed the steps, by this time you will have the following file structure.

7

Converting SASS code into CSS code

To convert the SASS code into CSS code, we’re going to use the -watch command in command prompt. This will compile the SASS codes to CSS. Additionally, this will also watch the directories for changes or updates. Let’s try to convert  the SASS file to CSS file. Before we start, we need to put a sample code on our style.scss to see if this working.  Copy and paste the following sample SASS code on the stye.scss file you created under SASS folder.

1
2
3
4
5
6
7
8
$myMargin: 0px auto;
$myColor: red;
$myWidth: 600px;
h1 {
    color: $myColor;
    myMargin: $myMargin;
}

Next, open your command prompt and then go to the location where you put your files in. In my case, I put it in my desktop so I will type in cd “Desktop” and it will locate the desktop directory.

8

Now that we are in the desktop file directory, type in the sass –watch Sass:Sass 9

Using –watch command, we will convert all of the .scss files on the folder SASS. It will also watch for the changes or updates on the file. Notice that there are two SASS, divided by a colon. The first one represents the current location of the .scss file while the second one represents the location of the output of the file. Make sure you link the converted CSS file to your HTML file to see this working.

 10

Using Variables

SASS variables are declared using the $ character and are defined like CSS values. Using SASS, you can declare variables for styles like font size, margin, padding and so on. Using variables and giving it a style value makes it easy to reuse a style repeatedly.

There are six different types of variables you can use with SASS.

  1. Strings (e.g. $myString: “your text here”;)
  2. Numbers (e.g. $myNum: 10px;)
  3. Colors (e.g. $myColor: white;)
  4. Booleans (e.g. $myBool: true;)
  5. Lists (e.g. $myItemList: 1px solid red;)
  6. Nulls (e.g. $myVar: null;)

Let’s put some of these types into practice. Open up your style.scss file and type the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$myColor: #009a82;
$myString: " some text here ";
$myFontSize: 13px;
$myMargin: 0px auto;
$myWidth: 460px;
h1 {
    color: $myColor;
    margin: 0;
    padding: 0;
}
#container {
    width: $myWidth;
    margin: $myMargin;
}

Now when you run this code into your browser, you will have this output.

12

Nesting

SASS also allows you to define nested styles. This will let you write easy-to-read codes. For instance, you have the following CSS code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#container p {
   font-family: Arial;
   font-size: 13px;
}
#container h1 {
   font-family: Tahoma;
   font-size: 15px;
}
#container h2 {
   font-family: Helvetica;
   font-size: 14px;
}

For the SASS version, you will have a format like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$myFontsize1: 13px;
$myFontsize2: 18px;
$myFontsize3: 25px;
$myWidth: 500px;
$myMargin: 0px auto;
#container {
    width: $myWidth;
    margin: $myMargin;
    p {
        font-family: Arial;
        font-size: $myFontsize1;
    }
    h1 {
        font-family: Tahoma;
        font-size: $myFontsize3;
    }
    h2 {
        font-family: Helvetica;
        font-size: $myFontsize2;
}
}

Notice that we put all of the elements styles under the id container, instead of naming them one by one under the same element. If you run this code into your browser, you will have something like this.

12

Mixins

Mixins let you define common properties once then re-use them over and over again. Mixins are defined using @mixin directive and contains a block of codes and then reuse them using @include directive. Let’s put this into practice. Copy the code below to your style.scss file.

1
2
3
4
5
6
7
8
9
@mixin border {
   border: 1px solid red;
}
#container {
   width: 960px;
   margin: 0 auto;
   @include border;
}

As you can see, we use the @mixins directive to create a style for border and then we include the style to id container using @include directive. If you run this in your browser, you will have the output below.

13

Operators

Performing mathematical operations is one of the best features of pre-processors like SASS, something which you can’t do with just a normal CSS code. Given this feature allows you do more complex and dynamic codes. Let’s take a look at this how it works. Go ahead and open your style.scss file and copy and paste the code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$myColor: #aa30ff;
$myPadding: 20px;
$thickness: 1px;
$border: solid red;
#samplepara{
    color: $myColor;
    padding: $myPadding+30;
}
#list1 {
    color: $myColor;
    border: $thickness+5 $border;
}

As you can see, we perform mathematical computations by adding 30px on the padding. We also added border thickness of 5px on the border. If you run this in your browser, you can see the output will look like this.

14

Functions

SASS offers a variety of functions. A good example of this is the color functions where you can manipulate color styles. Check out the series of color functions below.

  1. darken(color, amount)
  2. lighten(color, amount)
  3. saturate(color, amount)
  4. desaturate(color, amount)
  5. alpha(color)

These are just series of examples of functions. To learn more about functions check out the SASS documentation. For now let’s go ahead and try this example to see how SASS functions work. Open your style.scss folder and then copy and paste the code below.

1
2
3
4
5
6
7
8
9
10
$myColor: #202020;
$myBackground: #e6e6e6;
body {
     background: darken($myBackground, 20%);
}
h1, h2 {
     color: lighten($myColor, 40%);
}

Notice that the color darkens by 20% using the darken function while the H1 lightens, and also the H2 text by 40% using the lighten functions. So if run this in your browser you can see similar output below.

15

SASS Output Formatting

One of the best features of SASS is it offers several options to control how the .scss code is formatted when compiled into CSS. Using the -style option command, we can perform formatting to our compile CSS code. The following are the SASS formatting styles.

Nested Format

Nested style is the default format of SASS. This format gives indention to all of the styles in your compiled CSS file. To see this in action, copy and paste the code below into your style.scss and then open your Command Prompt (make sure you are inside the directory of SASS) and type in SASS –update style.scss . This command will update the formatting for the compiled CSS file using the update command.

16

Now go ahead and open your compiled style.css file. As I’ve said above all of the styles will have proper indention.

  17

Expanded Format

This is the most user-friendly and readable format as the braces are properly expanded and each property will have its own line. Let’s see this in action. Using the same code above, open your command prompt and type sass –update style.scss –style expanded. Notice that we added –style command this is used to format compiled CSS file to a particular formatting.

18

So if you are going to look at the compiled CSS file on the SASS file, you can see the code formatting is similar to the image below. Notice that each property has its own line. The braces are also fully expanded.

19

Compact Format

This is the compact format output CSS code in a condensed but still readable format. It adds spaces between braces but all in one line. To see how this works using the same code above, open your command prompt and type sass –update style.scss –style compact .

20

If you are going to check the compiled CSS file, you can see something similar to the image below. It is condensed. Each property and style is in one line.

21

Compressed Format

The compressed format has minimized output. This is suitable for the production environment. This format has more condensed formatting. Using the same code, open your command prompt and type in sass –update style.scss –style compressed .

22

So if you are going to look at the compiled CSS file on the SASS file, you can see code formatting similar to the image below. As you can see, all codes are in one line with no spaces at all. 23

Conclusion

SASS offers a variety of ways to simplify your CSS issues. It allows you to reduce repetition of codes by using variables. SASS is powerful. This can help to improve the workflow of both web designer and web developers. Learn SASS now and discover how it can it help you build professional websites in a fast-paced development. Hope you enjoyed this tutorial and see you again next time.

AngularJS 2 way data binding


// any variable attached to $scope can have live representation in the view
myApp.controller('myController', function($scope){
    $scope.myAppModel = {
        firstName: 'Dave',
        occupation: 'UI Architect
    };
});

<!-- if we type in new values, they will display in real time -->
<div ng-controller="myController">
  <span> {{ myAppModel.firstName }} </span><br>
  <input type="text" name="firstName" ng-model="myAppModel.firstName">
  <span> {{ myAppModel.occupation}} </span><br>
  <input type="text" name="occupation" ng-model="myAppModel.occupation">
</div>

AngularJS currently accomplishes (view-model) data-binding via “dirty-checking”, a process of recursively comparing current data values for each $scope object with previous values to see what has changed if there has been an associated UI event or “watched” model event.

Basic comparison of jQuery and AngularJS

Tags


<!-- as a user types their name, show them their input in real time -->
<!-- the jQuery IMPERATIVE way -->
<form name="imperative">
  <label for="firstName">First name: </label>
  <input type="text" name="firstName" id="firstName">
  <span id="name-output"></span>
</form>

<script>
$(function(){
    // Notice how we must make sure the ID strings in both HTML
    // and JavaScript MUST match
    $('#firstName').keypress(function(){
        // boilerplate: retrieve a model value
        var nameValue = $('#firstName').value();
        // boilerplate: paint the model value into the view
        $('#name-output').text(nameValue);
    });
});
</script>

<!-- the AngularJS DECLARATIVE way -->
<form name="declarative">
  <label for="firstName">First name: </label>
  <!-- the next two lines create the 2-way binding between the model and view -->
  <input type="text" name="firstName" id="firstName" ng-model="firstName">
  <span>{{firstName}}</span>
</form>

<script>
// Because AngularJS hides the boilerplate, no DOM string references to maintain
// between HTML and JavaScript
</script>

 

How to break Javascript strings into multiple lines


There are two ways to break up a Javascript string into multiple lines: Backslashing and string concatenation.

String concatenation is often easier on your eyes, but slower and more memory intensive. If speed and performance is a goal than you should always delimit your JavaScript strings with backslashes and not plus signs.

Delimiting with backslashes

  1. var text = “Lorem ipsum dolor sit amet,\
  2. consectetur adipisicing elit,\
  3. sed do eiusmod tempor incididunt\
  4. ut labore et dolore magna aliqua.”;

Delimiting with string concatenation

  1. var text = “Lorem ipsum dolor sit amet,”
  2.          + “consectetur adipisicing elit,”
  3.          + “sed do eiusmod tempor incididunt”
  4.          + “ut labore et dolore magna aliqua.”;