Setting active element in css menu

59 views
Skip to first unread message

Mateusz Lewandowski

unread,
Jul 17, 2016, 4:33:01 PM7/17/16
to Dart Misc
Hi
How to add active class form menu item made in html with css like jquery does this way:
$('li a').click(function(e) {
        e.preventDefault();
        $('a').removeClass('active');
        $(this).addClass('active');
    });
for following simple menu?
<ul>
<li>
element
</li>
</ul>

Please help

Jan Mostert

unread,
Jul 18, 2016, 12:59:14 AM7/18/16
to Dart Misc

If you want to use jquery-like syntax, have a look at Dquery.

The Dart way is probably to do something like (I'm on my phone, so excuse syntax errors):

querySelectorAll('a li').forEach(ListElement li){
  If (shouldBeActive) 
    li.classes.add('active');
  else
    li.classes.clear(); // or try remove as well if you don't want to clear
}


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Jan Mostert

unread,
Jul 18, 2016, 1:01:35 AM7/18/16
to Dart Misc

Forgot to add li.onClick.listen(e){....}

Mateusz Lewandowski

unread,
Jul 18, 2016, 2:13:36 AM7/18/16
to mi...@dartlang.org
Thanks a lot for your response.
But how can i determine which element from the list item was clicked in dart approach?
I need this for set active class for proper element

Jan Mostert

unread,
Jul 18, 2016, 2:23:48 AM7/18/16
to mi...@dartlang.org
Wrote a quick DartPad example, plenty of scope for improvement, but this should give you and idea:
https://dartpad.dartlang.org/2d08514213aeadfe8345d5882fdb669e




Mateusz Lewandowski

unread,
Jul 27, 2016, 1:24:44 PM7/27/16
to mi...@dartlang.org
thanks a lot
sory for late

Reply all
Reply to author
Forward
0 new messages