What does a property / field of newHeader do?

I acknowledge that you are a JavaScript developer to create and paste (with strong experience in other languages). I use jQuery accordion and use cookies to save the selected section of the accordion. I found the code that I included in my code. The key section is as follows.

change: function (event, ui) { var index = $(this).find("h3").index(ui.newHeader[0]); $.cookie(accordion, index); } 

This works, but I hate using code that I don't understand. I understand that the index is detected using the find method (which makes the assumption that I don't have h3s in the content), but I don’t understand what ui.newHeader [0] does. What is the newHeader array and what is its purpose here?

Thanks Erick

+4
source share
2 answers

Looking at the source jquery.ui.accordion.js, it is just an object containing the newly selected item.

You can see for yourself if you just look at the source:

 // find elements to show and hide var toShow = clicked.next(), toHide = this.active.next(), data = { options: options, newHeader: clickedIsActive && options.collapsible ? $([]) : clicked, oldHeader: this.active, newContent: clickedIsActive && options.collapsible ? $([]) : toShow, oldContent: toHide }, down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] ); this.active = clickedIsActive ? $([]) : clicked; this._toggle( toShow, toHide, data, clickedIsActive, down ); return; }, 

newHeader is not an array, it is an object that represents the new selected item. The code you sent finds all the h3 elements in the accordion element, and then it takes the newHeader index. The element that newHeader represents changes every time the accordion changes.

+3
source

It is displayed with a widget on the accordion. The newheader property contains the title of the activated element that the accordion opened.

See also doc for change event.

+1
source

All Articles