RUVIDEO
Поделитесь видео 🙏

Single Function to Handle Multiple Elements at Same Page (this, closest, find, stop, execute)

How to use single function to handle multiple elements at the same page in jQuery? My technical manager asked me to create a toggle functionality. I created it right away. But it was good for one element. If I took copy of that code block and looked at result, both code blocks were responding to one click. I could not use multiple toggles for that function at same page. In this video we are fixing that.

Only clicked block should be toggled, and not the other. The issue was because we targeted generic classes and did not took into consideration which block was triggered at first place. There should be a control to identify which block was triggered and only that block should be toggled or respond to click.

This tip is not just for toggle. Whenever you create something, make sure you keep in mind that there may be copies of that code block. For example you may need more than one toggle or accordion or something like that on a single page. Only that thing should respond to click that was triggered and not its copy or duplicate. This is very important lesson.

We will use jQuery document ready to call our function. Outside that we will write that function. In this example following methods and keyword play important role.

- 'this' keyword
- jQuery closest
- jQuery find
- jQuery stop (I forgot to mention it)
- jQuery toggle
- jQuery slideToggle

When we click at title of our card, by using 'this' keyword we get only that element which was clicked. Then we grab its closest outer element that is toggle-wrap and we find toggle-area inside it. Then we toggle it. After find you can use jQuery 'stop' method for precaution.

Remember this keyword, closest and find in jQuery. Use these to lock an area and do something only inside that area. It will not affect other similar elements at the page. Only current block of code will respond to click in this technique. And this is how you overcome this issue. By using this technique, you can code functionality once and apply it for multiple elements at same page.

!!! I forgot one thing to mention in this video. If your function is repeating or going in a loop before stopping, use stop jQuery method 'stop()' after you use 'find()' jQuery method. Chain it after find() and you will be good.

Here is stop() method
https://youtu.be/X9U6NqOGlWA

✅ How To Hide / Protect JavaScript Code - Techniques and Tools
https://youtu.be/8VyzRlxo2-k
✅ React JS UNDEFINED Solution | Reactjs Learning | Learn ReactJS & JavaScript Debugging Fast
https://youtu.be/0IvxCxcEBPo
✅ Calculate Sum or Total from Values in Array & Array Object | Learn JavaScript | Reduce Method
https://youtu.be/Xw7G2b80dDg
✅ Get URL Parameters in JavaScript | URLSearchParams
https://youtu.be/CZP1iQFQjEY
✅ DIV to PDF, Iframe to PDF using JavaScript Only (with CSS & Images Support)
https://youtu.be/DV2tAG5E-F0
✅ How To UnMinify JavaScript Minified Files Easily | Decrypt Complex JavaScript Code
https://youtu.be/uh8_Rt4Qam8
✅ Toggle Class in Vanilla JavaScript | Learn JavaScript
https://youtu.be/IdtwowBlfmI
✅ How to Execute a JavaScript File by using NPM
https://youtu.be/2xcoenAdSWs
✅ Get User's Location (Country, State, City) with Free Unlimited API Access | PHP & JavaScript
https://youtu.be/_P8_JUaoNgs
✅ Replace jQuery with Vanilla JavaScript Code Easily | jQuery vs JavaScript
https://youtu.be/toJ3vRUMf2g
✅ Toggle in Vanilla JavaScript
https://youtu.be/ebDCyf-JFOw
✅ MINIFY JAVASCRIPT FILES & FOLDERS in Multiple Ways (Command Line & Code Editor)
https://youtu.be/umVoV4ak0HA
✅ JavaScript vs jQuery | Difference between JavaScript and jQuery
https://youtu.be/PrBSuz7rPlc
✅ JavaScript Variable Redeclare & Reassign | VAR vs LET vs CONST | Practical Examples
https://youtu.be/9NNva3x0awQ

Thank You!
Channel Support
? LIKE VIDEO
? SUBSCRIBE
? PRESS BELL ICON
✍️ COMMENT

Channel: https://www.youtube.com/webstylepress
Website: https://www.webstylepress.com
FaceBook: https://www.facebook.com/webstylepress/
Twitter: https://twitter.com/webstylepress
Instagram: https://www.instagram.com/webstylepress
LinkedIn: https://www.linkedin.com/company/webstylepress
GitHub: https://github.com/webstylepress
#jquery #javascript #webdevelopment #js #webstylepress #functions #methods

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Single Function to Handle Multiple Elements at Same Page (this, closest, find, stop, execute)», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.