0

I'm trying to use a JavaScript function on an Oracle Apex webpage. The object is to have a link which when initially clicked, opens all subregions and when clicked again, closes all subregions. Essentially, a simple toggle. The function is below:

initContentFrameTabs = function(){
$('div.uFrameRegionSelector > ul li a').click(function(e){
e.preventDefault();
link = $(this);
subregions = link.parents('.uFrameMain').find('section.uHideShowRegion');
link.parents("ul").find('li a').removeClass('active')

if (link.hasClass('showAllLink')) {
   expandAllSections();
   // subregions.show();
   link.addClass('active');
   document.getElementById('Title').innerHTML = 'Hide All';
 } else if (link.hasClass('active')) {
   hideAllSections();
   link.parents("ul").find('li a').removeClass('active')
   document.getElementById('Title').innerHTML = 'Show All';
 } else {
   expandSection(link.attr('id').substr(4));
   // subregions.hide();
   // $('#'+link.attr('id').substr(4)).show();
   link.addClass('active')
 }
})
}

It seems to work initially, as I click on my link, it opens all sub regions and the text changes to reflect it's new function, ie, Hide All.
However, from that point on, it doesn't work. I receive an error at that point, being:

Uncaught TypeError: Cannot call method 'substr' of undefined

It claims this error is being throw at my substring line, just after the else clause.
Can anyone shed some light on why this is happening?

1 Answer 1

1

Well, it looks like link.attr('id') is undefined. So I would take a look to see if that link still has an ID attribute after your initial click. Chances are, the link was recreated and it wasn't created with an id the second time.

First though, after your link, open up your DOM and see if the link still has the attribute.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.