I am loading content into my page from another page on my site using jq .load() on a click event.
This is working fine, but I want to check the document for the class of the element that is loaded first before the content is loaded into the page in case the load has already been done.
This is because there will be more than one click event on the page that can call the content.
I have elements that initiate the click function which I have given the 'tittle' attribute matching the class of the element that is to be loaded.
For example, if the element that I am loading into the page has the class 'loadedContent'
I give each of the click elements that call this content the title 'loaded content'
I am then getting this title from the click element, searching the document to see if there is any element that has a class matching that title.
If there is an element already loaded on the page with a class matching the title, then I won't execute the load code. If there isn't, then the .load() function will execute.
Currently I am obtaining the 'title' attribute from the click element, but I am unable to successfully search the document for a matching class.
The code I thought should be simple, and currently have (after the click event):
var getLabel = $(this).parent().attr( "title" );
if ($(document).hasClass( getLabel )) {
// do a function
} else {
// perform load of content
}
my load function is appending to the body, do could potentially use body instead of document but either is not working.
Not really sure where I should go from here as it should work.
Thanks
Richard
Aucun commentaire:
Enregistrer un commentaire