Hi,

I have an Array called folderArray and I am iterating through using $.each. each element in the folderArray is a URL string. so below script builds a folder hierarchy. However, what I want to do is I want to execute showModal(this) when a user clicks on the anchor. but it is not working. showModal(this) i think it is getting confused with "this" alternatively I tried href= javascript:showModal(this) that also does not work ..please anyone help




//iterate through array
$.each(folderArray, function () {


var parent = elements[this.substring(0, this.lastIndexOf("/"))]

//if there exists a parent then create a new list.
var list = parent ? parent.next() : rootDiv;

if (!list.length) {

list = $("<div style='margin-left:50px;'></div>").insertAfter(parent);


}

var item = $("<div style='margin-left:50px;'></div>").appendTo(list);

var anchor = $("<a target='_blank'></a>").attr("onclick", showModal(this)).text(this.substring(this.lastIndexOf("/") + 1)).appendTo(item);


var folderIcon = $("<img border='0' src='_layouts/Images/folder.gif'/>").prependTo(anchor);


elements[this] = item;


});


function DialogCallback(dialogResult, returnValue){ }

//Open the Form Dialog
function showModal(windowUrl){
var options = { url:windowUrl,
width: 700,
height: 700,
dialogReturnValueCallback: DialogCallback
};
SP.UI.ModalDialog.showModalDialog(options);

}