JavaScript handle bootstrap list-group click

I'm stuck with html/JS and have no idea how I should handle some events. For example I have a list-group:

<div class="col-lg-3 col-md-3 col-sm-3 opciones">
   <div class="list-group">
      <a target='_blank' href="#" class="list-group-item active">
        Tokyo 
      </a>  // barfoobarfoo
      <a target='_blank' href="#" class="list-group-item">London</a> // foo
      <a target='_blank' href="#" class="list-group-item">Paris</a>  // bar
      <a target='_blank' href="#" class="list-group-item">Moscow</a>  // foobar
      <a target='_blank' href="#" class="list-group-item">NY</a>   //foobarfoo
    </div>
</div>

What I want to do is:

1)change active elements on click.

2)call JS function when element is clicked. UPD: So now I know that click events can be handled with JQuery thing.

What I can't understand is to how to determinate which element is clicked. For example JQuery:

$('.list-group-item').on('click', function() {
    $this = $(this);

    $('.active').removeClass('active');
    $this.toggleClass('active')

   function simpleFunc(someargument) { //value of this argument depends on clicked item and can be (foo|bar|foobar ) etc
       document.write(someargument) // here whould be written some text (foo|bar|foobar ) etc
})

There are no tutorials or anything, except this HTML code. Thanks

Answer:1

You can simply use jQuery for this.

For example:

$('.list-group-item').on('click', function() {
    var $this = $(this);
    var $alias = $this.data('alias');

    $('.active').removeClass('active');
    $this.toggleClass('active')

    // Pass clicked link element to another function
    myfunction($this, $alias)
})

function myfunction($this,  $alias) {
    console.log($this.text());  // Will log Paris | France | etc...

    console.log($alias);  // Will output whatever is in data-alias=""
}

Alias would be captures as such:

<a data-alias="Some Alias Here">Link<\a>
Answer:2

Here is dynamic jQuery code

$(document).ready(function() {
  $(".list-group-item").live('click', function(){ 
    $('.active').removeClass('active');
    $(this).addClass('active');
    console.log($(this).html()); 
    // Code here whatever you want or you can call other function here
  });
});

This will help you. Enjoy!

Answer:3

How can I modify the class list via jQuery or JavaScript for multiple classes in one step? I have several classes in my form like <div class="form-group has-error has-feedback">...</div> ...

How can I modify the class list via jQuery or JavaScript for multiple classes in one step? I have several classes in my form like <div class="form-group has-error has-feedback">...</div> ...

  1. javascript modify class list

How can I achieve that users can add multiply custom if-statements? For example let's say there is a given variable called x with a given value of let's say 8. The user sees that x = 8 and has a ...

How can I achieve that users can add multiply custom if-statements? For example let's say there is a given variable called x with a given value of let's say 8. The user sees that x = 8 and has a ...

I am writing a chrome extension to replace all the occurrences of certain set of image ( I have the image names) and replace it with another image (src) I need to find all the occurrences of a ...

I am writing a chrome extension to replace all the occurrences of certain set of image ( I have the image names) and replace it with another image (src) I need to find all the occurrences of a ...

  1. find image name in word
  2. find image name on google
  3. find image name in powerpoint 2016
  4. find image name
  5. find image name in powerpoint
  6. find image name in pdf
  7. find image name on iphone
  8. find image name jquery
  9. find docker image name
  10. tasklist find image name
  11. azure find image name
  12. dism find image name
  13. find image file name
  14. xcode find image name
  15. upload image find name
  16. find facebook from image name
  17. how to find image name in excel
  18. find image to font name
  19. find your name image
  20. unity find image by name

Hoping one of you guys can help me here. I'm trying to import data into excel from this webpage as well as some others that are the same website: https://re.po.st/qZZYQJ - basically I want to take ...

Hoping one of you guys can help me here. I'm trying to import data into excel from this webpage as well as some others that are the same website: https://re.po.st/qZZYQJ - basically I want to take ...

  1. scrape html page python
  2. scrape html page php
  3. scrape html page javascript
  4. scrape html page
  5. scrape html page c#
  6. java scrape html page
  7. scrapy scrape html page
  8. html page scrape example