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 href="#" class="list-group-item active">
Tokyo
</a> // barfoobarfoo
<a href="#" class="list-group-item">London</a> // foo
<a href="#" class="list-group-item">Paris</a> // bar
<a href="#" class="list-group-item">Moscow</a> // foobar
<a 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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With