logo
down
shadow

Looking to simplify my jquery


Looking to simplify my jquery

By : Michael Holste
Date : November 21 2020, 01:01 AM
should help you out Without sufficient information from the OP (extensibility, purpose and etc), and without further information about which part of the replaced content should be static or dynamic, my answer only aims to replicate the behavior as observed in OP's original fiddle.
If the only difference is the number that comes at the end of each string, you can simply store that number in a HTML5 data- attribute, and use a universal click event. The markup can be updated as follow:
code :
<div class="cont">
    <div class="button"><</div>
    <div class="third">
        <ul class="bbul">
        <li id="bbone" data-value="1">ONE</li>
        <li id="bbtwo" data-value="2">TWO</li>
        <li id="bbthree" data-value="3">THREE</li>
        </ul>
    </div>
    <div class="doub">
        <div id="a"><span>This is a first sample</span> <span class="value"></span></div>
        <div id="b"><span>This is a second sample</span> <span class="value"></span></div>
        <div id="c"><span>This is a third sample</span> <span class="value"></span></div>
    </div>
</div>
$('.bbul li').click(function() {
    $('.doub div .value').html($(this).attr('data-value'));
});


Share : facebook icon twitter icon
Why wrap a DOM element in jQuery if doesn't simplify things? (Example from jQuery Cookbook)

Why wrap a DOM element in jQuery if doesn't simplify things? (Example from jQuery Cookbook)


By : sen
Date : March 29 2020, 07:55 AM
I hope this helps . One of jQuery's primary goals is to act as a consistent layer between the programmer and the potentially unpredictable browser-defined functions. So yes, it is generally best practice to use the jQuery wrappings to any DOM functions.
Simplify jQuery Code Simplify

Simplify jQuery Code Simplify


By : manh hoang
Date : March 29 2020, 07:55 AM
I wish this help you , what you can do is:
code :
var section=4*~~(index/4);
$('.brands li:nth-child('+section+')').append('<span>new li</span>');
Trying to avoid repetition, simplify ... create global variables and simplify my javascript -- pure js no jquery

Trying to avoid repetition, simplify ... create global variables and simplify my javascript -- pure js no jquery


By : Ismael Ortiz Osuna
Date : March 29 2020, 07:55 AM
I hope this helps .
code :
var $ = document.getElementById;
var $ = document.getElementById.bind(document);
How do I simplify this jQuery?

How do I simplify this jQuery?


By : Nathan Eckenrode
Date : March 29 2020, 07:55 AM
hope this fix your issue Since you're looking at all the a elements under #thumbnav, you don't need individual selectors:
code :
$('#thumbnav a').click(function() {
  currPhoto = this.id;  // `this` will be the clicked `a` element
});
How can I simplify my jQuery?

How can I simplify my jQuery?


By : Swapnil Katkar
Date : March 29 2020, 07:55 AM
this will help Give all your
Related Posts Related Posts :
  • grab non-sibling element with jquery
  • Select a word and click it
  • Trigger modal instead redirect to /users/sign_in path, Rails 4 with devise
  • Combining Parent theme JS and CSS
  • Angular ui-grid - DropDown Selection shows Id
  • jquery addclass when there is content on body
  • JQUERY : CSS does not apply to dynamically created elements
  • Bootstrap multiselect dropdown checkbox not working on paginated table
  • JQuery scroll to dynamic id
  • Jquery first time tried ajax
  • Disable the link on the active tab (Bootstrap)
  • How to handle this validation when a div is added?
  • how to show/hide and check/uncheck checkboxes dynamically inside kendo grid
  • Conditional parameters for AJAX function
  • Jquery add class to input checkbox field
  • Bootstrap countdown timer Jquery
  • Open the closest modal of jQuery clicked element
  • change background color of specific button on click
  • Can I create link as post to 3rd party site and open in new tab?
  • ID is 'undefined' using .each()
  • Using .each() for targeting each child differently in Jquery
  • How to return data from functions in function
  • Execute this jquery only when viewport is bigger than
  • Bootbox showing white box behind dialog
  • Toggle multiple classes with prevAll(), nextAll(), slice(), and duplicate classes... better way?
  • Show/hide list items and add more/less link
  • Going through all occurences of class on slider change
  • Call jQuery valid() without updating the screen
  • hide and show ActionLink and save data in database - MVC
  • Pass each object in JSON array to query
  • Toggling content div on one-page site with jQuery
  • Foundation Equalizer is setting height to inherit?
  • carousel navigation each function
  • changing color of text color with input slider
  • jquery: filter using AND OR in selector
  • Call a function If any Item is chosen From select box , After Dom update
  • Target class within a jquery object
  • How to scroll a web page with fixed navigation bar just before arrive to a section or div?
  • How to add a class name to a specific selector
  • How to prevent background scrolling
  • How can I disable previous/next in OwlCarousel2 if there aren't enough items to scroll?
  • How to pass products and quantities to ASP.NET MVC4 Web API from form submit
  • jQuery css3 attribute not working
  • WordPress One Page Style Menus Scrolling
  • jquery.unobtrusive-ajax.js is not capturing the Submit event
  • Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'
  • can't get correct checkbox value
  • jquery tooltipster plugin, hide all tips?
  • How to set 3 different colors at jQuery UI Slider
  • How to convert a string to html and add a event, descard after use?
  • How can I make jQuery wait for div display value to change to "block", then make ajax call?
  • Stellar.js giving uncaught type error
  • Saving form data to local storage and show it on refresh
  • Jquery carousel not being implemented
  • Use modal with external URL body and dynamic links from data attribute
  • Bootstrap datepicker query?
  • Navbar/header animated change on scroll
  • Bootstrap paginated table sending only 10 row's data to server
  • Bootstrap 3.0 & NiceScroll 3.5.0
  • Find me all inputs where ID ends with xyz except for a particular ID
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org