Discussions

Q2回目以降のclickイベントが発生しない

【やりたいこと】
クリックされた都道府県をもう一度クリックすると、市町村が隠れるようにしたい。
具体的には、宮城県の市町村の数が増えてきて見づらいので、宮城県をクリックした後にもう一度宮城県をクリックすると市町村を隠せるようにしたい。

【問題】
クリックしたオブジェクトをもう一度クリックしても、イベントが発生しない。
例えば、コード中のaccordion関数にslideToggle()を書くと、上下のスライドを実現できるはずだけど、2回目以降のclickイベントが発生しない。

ご教示のほど、よろしくお願いします。
不明点ございましたら、メッセージをいただければお答えします。

Sample Code

AAnswer to: 2回目以降のclickイベントが発生しない

kyo_ago

修正してみましたー
こんな感じでどうでしょうか?

以下の部分を変更しています。

1. accordion内で閉じていた場合の処理を追加
2. switchMapが.prefを含む全てのaに呼ばれていたので.cityのみに制限
3. preventDefaultでイベントをキャンセル

naoty

完璧です!有難うございます。
return falseとprevent Defaultの区別がついていなかったです。あと、イベントを呼び出すオブジェクトにも配慮しないと予期せぬイベントも発生させてしまうことも理解しました。

さっそく修正しました。

farhan

Interesting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I'll be sure to check back again real soon.
placemats for kids

farhan

Thank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info.
Vidassoft

ssxxxccc

I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well!
Easel stands

farhan

Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
Reflexology in Glendora

smith655

John Smith is a self-professed security expert; he has been making the people aware of the security threats. His passion is to write about Cyber security, cryptography, malware, social engineering, internet and new media. He writes for Norton security products at mcafee.com/activate and Office.com/setup


smith655

Office.com/setup - Everybody who has a computer or knows how to work on one has used Microsoft Office at some point or the other. . Office.com/setup-When computers first entered the world, in the 1940s, they consisted of vacuum tubes. Office.com/setup-Microsoft Office has thought of a dash of latest updates in its applications, for instance, Word, Excel, PowerPoint, Access, and others

Post a question

You can post JavaScript, HTML, CSS related questions with attached reference to actual codes and get the answers likewise.

Ask a question

  • 1. Click the ‘Post a question’ above

  • 2. Enter question details, reference code, and click ‘Add question’ button

  • 3. Question will be paired with the code on display

Add an answer

  • 1. Choose a question

  • 2. Enter answer details, attach the reference code and click ‘add answer’ button

  • 3. Your answer will accompanied with attached code

Tag