H
H
hottab_12017-07-07 14:08:12
JavaScript
hottab_1, 2017-07-07 14:08:12

Incorrect work of JS on mobile, how to solve the problem?

Hello!
The site implements the disclosure functionality when clicking on a block, that is, when you click on element1, another element2 is shown, when you click on element1 again, element2 is hidden.
Implemented with the following JS code:

$('.raz').on('click', function(){
    var $that = $(this),
        nc = $that.next('.del').length,
        block = nc ? $that.next('.del') : $that.parent('.del');
    block.slideToggle(function(){
        $('.raz',block).add(block.prev('.raz'))
        .text(block.is(':visible') ? 'Скрыть' : 'Показать номер телефона');
    });  
});

Everything works fine, but there is one "But", on a mobile device, element2 is shown immediately and if you click on element1, it will hide element2, that is, JS works. But why is it shown immediately in the expanded state?
How can I make it work like on the full version of the site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-07-13
@servdo

It is not clear how you have properties on the elements. Post it on https://jsfiddle.net/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question