Hello all, just going through the jquery api and trying things out.
this is not quite working.
I check for the title of the page, alert the title on reload.
but when i went to change some elements if the title matches the pages it is on. It does nothing.
jQuery(document).ready(function () {
var $title = jQuery(this).attr('title');
alert(title);
if (document.prop('title','Resources | digital') == $title){
$( "a" ).wrap( '<div class="testClass"></div>' );
};
});
In your above page you are attempting to actually change the page title, and only fail at doing that due to a misunderstanding of how jQuery is used.
If you want to use jQuery methods to check the page title, you will have to turn document in to a jQuery resource.
if ($(document).prop('title') === 'Resources | digital') {
...
}
And, it’s even easier to achieve just by using standard JavaScript
if (document.title === 'Resources | digital') {
...
}
I can’t help but feel though that checking the title of the page is a brittle technique, and that there has to be a more robust manner in which to achieve the same result.
Yes, and it also means that the script is on all other pages that don’t need the change too.
What sort of system is being used to build the pages? Most of them have ways for custom content (such as a separate script) to be included on certain pages.
lately i just have been using wp at work we have wp & cq5/AEM
but this exercise was just for me so i can get a better grasp of jquery in general.
went to the jquery api doc and thought i’d start working my way down.
Was also curious as to grab a specific page if needed.
so if i was in wp and wanted to only affect one page w/the code i could grab that page w/jquery