Jump to content

[SOLVED] can anybody explain 5 short lines of JS code to me??


cluce

Recommended Posts

need help on what this lines are doing?

 

// create a link with an onClick event which will

// control the sorting of the table

var linkEl = createElement('a');

linkEl.href = '#';

linkEl.onclick = this.headingClicked;

linkEl.setAttribute('columnId', i);

linkEl.title = 'Click to sort';

 

need help on what this lines are doing?

 

// create a link with an onClick event which will

// control the sorting of the table

var linkEl = createElement('a');

linkEl.href = '#';

linkEl.onclick = this.headingClicked;

linkEl.setAttribute('columnId', i);

linkEl.title = 'Click to sort';

 

 

Step by step:

var linkEl = createElement('a');

 

The variable linkEl now contains an HTML anchor/link element.

 

linkEl.href = '#';

 

The href attribute of the link is set to '#.'

 

linkEl.onclick = this.headingClicked;

 

This assigns linkEl's onclick event handler the function headingClicked();  Whenever the link that linkEl holds is clicked, that function will execute (providing it was coded correctly).

 

linkEl.setAttribute('columnId', i);

 

This creates the attribute 'columnId' for the link, and sets the value to whatever is currently in the 'i' variable.  I can only assume that this code is executed within a for-loop whose job is to create a table with these links.

 

linkEl.title = 'Click to sort';

 

The last line assigns the text 'Click to sort' to the link's title attribute.  If the link is moused over, this text will appear near the mouse pointer.

 

Hope this helps! :)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.