Search code examples
javascriptjqueryhtmlhover

How to enable tab and its content on click of a text in javascript/jquery?


I am working on a website on which I want enable button on click of a text in Javascript/Jquery.

The JQuery code which I have used in order to scroll down towards the bottom on clicking view options text are:

$(".view_profile_options a").click(function(event) {
    event.preventDefault();
    var sectionTop = $('.tab-contents').offset().top;
    $('html,body').animate({
        scrollTop: sectionTop },
        'slow');
 });


Problem Statement:

I am wondering what changes I should make in the JQuery code above so that on clicking view options text in the fiddle, the hover for tokyo and its content gets enabled automatically.


Solution

  • This works like a charm:

    $(".view_profile_options a").click(function(event) {
        event.preventDefault();
        var sectionTop = $('.tab-contents').offset().top;
        
        var event = $.Event('click');
        event.currentTarget = $('.tab .tablinks')[2];
        
        $('.tab .tablinks:nth-child(3)').trigger(event);
    
        $('html,body').animate({
            scrollTop: sectionTop },
            'slow');
     });