Data taget and click function

I try to execute click function based on data target and not a class such as

<div id="service1" class="modal-box"> 

but using data-target=“#modal-box

<li class=""><a class="" data-toggle="collapse" data-target="#modal-box"></a></li>

and click function:

        $('#modal-box').click(function() {

Is this technically possible or class/ID should be used?

You can use an attribute selector, such as the following:

$('[data-target="#modal-box"]').click(function() {

Thank you for the message!

When using data-target, it should be used also hasClass open from bootstrap.

Is there possibility to link class with the name OPEN and data-target as Bootstrap will add OPEN?
I try to close modal container if it is clicked outside area:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.