jquery101
jquery101

Reputation: 3

error on removing char from variable

please advise on what to change in syntax

            $(document).ready(function(){
                //click on nav
                $('#nav li a').click(function() {
                    //set variable
                    var targetDiv = $(this).attr('href');
                    var targetPic = $(this).attr('href');
                    //remove # from var
                    targetPic = str.replace('#', '');
                    //hide !=var
                    $('div').not( + targetDiv) .hide('puff', 1000);
                    $('div').not('.' + targetPic) .hide('puff', 1000);
                    //show =var
                    $('div' + targetDiv) .show('puff', 1000);
                    $('div.' + targetPic) .show('puff', 1000);
                    })

            });

Upvotes: 0

Views: 60

Answers (2)

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

targetPic = str.replace('#', '');

should be

targetPic = targetPic.replace('#', '');

since there is no variable str imho

but this code will not work in browsers where $(this).attr('href');returns the full absolute url (thiat is including http://......#) like some versions of IE

Upvotes: 1

Dhruva Sagar
Dhruva Sagar

Reputation: 7307

To @Caspar Kleijne's answer I would also like to add that I see another mistake in your code :

$('div').not( + targetDiv) .hide('puff', 1000);

should probably be

$('div').not('#' + targetDiv) .hide('puff', 1000);

Upvotes: 1

Related Questions