user1750781
user1750781

Reputation: 1

Uncaught TypeError: Cannot call method 'css' of null (anonymous function) - Joomla 1.5

My problem is that the Cookie Law bar won't hide... http://www.kasedesign.co.uk/scc/

The same code hides fine on other websites I've done, such as http://www.kasedesign.co.uk/spa/ I've not used this code on a Joomla website before though.

I read on here that containing the script within a Window OnLoad might help and it got rid of my error, but the cookie bar didn't hide.

Can anyone point me in the right direction?

Upvotes: 0

Views: 3031

Answers (2)

user1750781
user1750781

Reputation: 1

Thanks for your help... I realised there is a cookie script being called that doesn't exist in the spa bathrooms site. I will address that.

I tried your solutions, but they did not help.

Someone mentioned earlier that a jQuery conflict may be causing my problem, but has since deleted their comment.

I therefore added the following... jQuery.noConflict();

I then replaced $ for jQuery and all is working fine.

Thank you to anyone that took time to look into this problem!

Upvotes: 0

Cyril ALFARO
Cyril ALFARO

Reputation: 1681

On your spa website, the file js/cookielaw.js is not called, indeed it is invoked by relative url and /spa/js/cookielaw.js return a 404 error, so no code are loaded.

On your other website (about cars), the url is absolute : /scc/js/cookielaw.js so the script is loaded.

The issue is that DOM is not ready when you call that script, so jQuery return the error.

Try to change begin of script from :

// Cookie Law
// -----------------------------------------------------------------------------

$('html').css('padding-top','35px');
$('.cookiedisclaimer').show();

(function($) {
    //...

to

// Cookie Law
// -----------------------------------------------------------------------------

(function($) {

    $('html').css('padding-top','35px');
    $('.cookiedisclaimer').show();
    //...

It's the easier and faster way to fix.

A cleaner way is to start your script like that :

// Cookie Law
// -----------------------------------------------------------------------------

$(document).ready(function() {
    $('html').css('padding-top','35px');
    $('.cookiedisclaimer').show();
}) ;

(function($) {
    //...

Upvotes: 1

Related Questions