jquery-ui tabs getting anchor href with older jquery 1.8

101 Views Asked by At

I have had a look around and sorry if I have missed the answer. Came across this post. And a few others circulating now on SO and wondered if there was an easier way:

The problem:

<ul>
<li><a id="test1" href="/someurl">click1</a></li>
<li><a href="/someurl2">click1</a></li>
<li><a href="/someurl3">click1</a></li>
</ul>

Followed by

<ul id="ui-tabs-1" ></ul>
<ul id="ui-tabs-2" ></ul>

Everything is working what I am trying to do is alter the url in any given selected li from href="/someurl" to href="/someurl?params=something"

   var href = $('#test1').attr('href')
    console.log('link is  '+href)
     //this returns correct link
$('#tabs').on('refreshListing',function(event,target) {
     $(this).tabs('load',$(this).tabs('option','selected'));

    var href = $('#test1').attr('href')
    console.log('link is  '+href)
    //this returns  #ui-tabs-1
});

At the moment the above function simply reloads the url, when attempting to get url of li I get #ui-tabs-1 not /someurl

There are some weird stuff going on above in the refreshListing the value of actual ID link in a href is converted and ultimately before it does the load on that tab id I wish for it access new url rather than well at the moment it is hard to tell what on earth is driving all this oddness

1

There are 1 best solutions below

0
On

Never mind solved it, the issue was a little more complex than described.

You have tabs that are dynamic but also have a search form in above

$('#tabSpecific').on('refreshListing',function(event,target) {
//This was previously 
//var obj = $('#search')
//Now changed to - this to fix underlying (above issue)
  var obj = $('#search').find("input").not("input[type='hidden']").filter(function() {
            return this.value;
        });

  if (obj.length > 1) {
    obj.trigger('submit');
  } else {
    $(this).tabs('load',$(this).tabs('option','selected'));
  }
})

The problem had been it was always returning a size greater than 1 (due to other complications of multi tabs sharing same common things) so it hit the submit feature which submitted - page through search form of tab - this then didn't reload actual tab when required....

Anyhow it is hard to express it all but the above fixes behaviour to how I need it to work - only when it actually has search it will submit otherwise it will reload which should work correct for my situation