Information:
So I have created a page on my site that will act as a contact page/org chart for my department. I have a SharePoint List that stores all the relevant data such as name, dept, title, email, phone, ect.
I wrote some JavaScript to get the data from the List, create the code, and append it to the page. This part works fine and I have no problem with it; however, I also have a section of JS that will expand and collapse the additional contact information of the individual by clicking a button
Problem:
The section of JavaScript that expands and collapses the contact information will not work. I'm not sure if I'm just overlooking something or what.
(This problem is independent of the browser... It does not work in IE, Chrome, or FF)
Full Code: (within the script tags of the page)
$('.expand').click(function() {
$(this).parent(".contact-box").toggleClass('expanded');
$(this).siblings('.information').find('.phone, .email').toggleClass('show');
});
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "The Team",
CAMLViewFields: "<ViewFields><FieldRef Name='FullName'/><FieldRef Name='JobTitle'/><FieldRef Name='Location'/><FieldRef Name='Email'/><FieldRef Name='Phone'/><FieldRef Name='ContactPhoto'/></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
$('' +
'<div class="contact-box">' +
' <div class="contact-img round">' +
' <img class="portrait bottom" src="'+$(this).attr("ows_ContactPhoto")+'" alt="Image">' +
' </div>' +
' <hr/>' +
' <div class="information">' +
' <p class="name">'+$(this).attr("ows_FullName")+'</p>' +
' <p class="position">'+$(this).attr("ows_JobTitle")+'</p>' +
' <p class ="location"><span class="fa fa-map-marker icons"></span>'+$(this).attr("ows_Location")+'</p>' +
' <p class="email show"><span class="fa fa-envelope icons"></span><a href="mailto:'+$(this).attr("ows_Email")+'"></a>'+$(this).attr("ows_Email")+'</p>' +
' <p class="phone show"><span class="fa fa-phone icons"></span>'+$(this).attr("ows_Phone")+'</p>' +
' </div>' +
' <div class="expand"><span class="fa fa-angle-down" aria-hidden="true"></span></div>' +
'</div>').appendTo('.container-box');
});
}
});
});
Problem Code:
This is the code that will not run on the page. If anyone can see what I'm doing wrong or if there is something within SharePoint that will not allow me to do this, I would appropriate the feedback.
$('.expand').click(function() {
$(this).parent(".box").toggleClass('expanded');
$(this).siblings('.information').find('.phone, .email').toggleClass('show');
});
$(document).ready()
, you are calling objects that may have not loaded on the page yet.