cluce Posted September 13, 2007 Share Posted September 13, 2007 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'; Quote Link to comment https://forums.phpfreaks.com/topic/69188-solved-can-anybody-explain-5-short-lines-of-js-code-to-me/ Share on other sites More sharing options...
KevinM1 Posted September 13, 2007 Share Posted September 13, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/69188-solved-can-anybody-explain-5-short-lines-of-js-code-to-me/#findComment-347747 Share on other sites More sharing options...
cluce Posted September 13, 2007 Author Share Posted September 13, 2007 thanks Quote Link to comment https://forums.phpfreaks.com/topic/69188-solved-can-anybody-explain-5-short-lines-of-js-code-to-me/#findComment-347864 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.