1

I have one doubt can i have an anchor tag in demo1.html page if i click that link it has to got to demo2.html page. In demo2.html page i am using a data filter and it has to select that filter can we do like that. Here is the sample code i amm using

Demo1.html

<a href="careers.html">Bangalore </a> | <a href="#"> Mumbai </a>

Demo2.html

<ul>
    <li class="filter"><a class="selected" href="#0" data-type="all">All</a></li>
    <li class="filter" data-filter=".bangalore"><a href="#0" data-type="bangalore">Bangalore</a></li>
    <li class="filter" data-filter=".mumbai"><a href="#0" data-type="mumbai">Mumbai</a></li>
</ul>
<ul>
    <li class="mix bangalore"></li>
    <li class="mix mumbai"></li>
</ul>

I am using this filter plugin. kindly help me out with this

Tushar
  • 85,780
  • 21
  • 159
  • 179

1 Answers1

0

First, make a function to get a querystring parameter like in How can I get query string values in JavaScript?

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Then update your links to

<a href="careers.html?dataType=bangalore">Bangalore </a> | <a href="#"> Mumbai </a>

and finally, target your elements in the new page

$('li.filter').filter(function(){
    return $(this).attr('data-type') == getParameterByName('dataType');
}).addClass('active');
Community
  • 1
  • 1
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53
  • Thanks AmmarCSE for the quick reply. can you same explain me in detail how to do this, I din't get your point clearly – Raj the Starter May 29 '15 at 09:23
  • @RajtheStarter, the first step is to update your anchor elements with the query string like ?dataType=bangalore – AmmarCSE May 29 '15 at 09:28
  • @RajtheStarter, the next step is to add the funciton getParameterByName to the Demo2.html and use it by filtering like the last code snippet in the answer – AmmarCSE May 29 '15 at 09:29