Ahmed Ahmed - 8 days ago 6
Javascript Question

Change div data by clicking

I want when click on stackoverflow then change data-float-toggle to hover not click.

Can we make this by something like this below code



jQuery('.top-bottom').on('click', function(e) {
'use strict';
e.preventDefault();
jQuery('.top-bottom').addClass('hide');
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="top-bottom" data-float-toggle="click">
<a href="#">stackoverflow</a>
</div>




Answer

How about this solution. Hope it helps!

$(document).ready(function () {
 $('.top-bottom').on('click', function(e) {
'use strict';
	e.preventDefault();
     $('.top-bottom').addClass('hide');
     $(this).attr('data-float-toggle', "hover");

});
});
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="top-bottom" data-float-toggle="click">
		<a href="#">stackoverflow</a>
</div>