Domanda

So i have a list of anchor tags that I am using for a filter. I am using jQuery to look for the appropriate data tag so when a name is clicked it will show all the work that a developer has completed from a list of all completed items. What i would like to make it elegant, is to have it default to the current user. So if Mike logs in, that the anchor link for Mike is clicked.

<a data-filter="dev-mike" href="#">Mike</a>
<a data-filter="dev-john" href="#">John</a>

Is there a way to have jQuery activate or enable an anchor tag on page load?

Some ideas that I was thinking in case this isn't possible was to have rails give the anchor tag that belongs to the current user a new data attribute called data-default. but then I'll still have to have use jQuery to select that tag as active?

È stato utile?

Soluzione

What you could do is redirect the user to that page after logging in with an anchor at the end of the url. For example:

www.mywebsitelandingpage.com#mike

Then to select one tag as active on page load, you can do something like that:

<a data-filter="dev-mike" class="<%= 'current' if current_user.name == "Mike" %>" href="#mike">Mike</a>
<a data-filter="dev-john" class="<%= 'current' if current_user.name == "John" %>" href="#john">John</a>

and then of course use some CSS to style the a tag with class="current"

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top