Hot answers tagged

5

You can change the selector to select all items at once. First option: select all ids comma separated: $('#C7-Drawer-Shelf-Combo,#T7-Drawer-Shelf-Combo,#C11-Drawer-Shelf-Combo').on('change', function () { if (this.value) { $(".under-drawer-bench").show(); } else { $(".under-drawer-bench").hide(); } }); Second option (...


4

Short review to make this more DRY Review the documentation on https://api.jquery.com/toggle/, this often helps with code like this Know that you can select multiple id's by separting selectors with a comma in jQuery You can chain jQuery commands, which can lead to either more or less readable code, it's an art. In this code, I feel there is not enough ...


3

Overall your code is readable and it is clear to me what you are trying to accomplish by reading the code alone. Your variable names describe their content, with one caveat described below. Bugs IP's The mask restricts which valid ip's you can enter into your textbox, namely only all valid ip's with 3 numbers for each octet. It also allows a wide range of ...


3

Some improvements: completely remove the JS function and replace with CSS (thanks to this SO answer); this greatly reduces loading time wrap one ruby for each pair rb & rt with ruby, instead of having multiple pairs of them inside ruby use flex to render rather than the default display: block The improved code: ruby { display: inline-flex; ...


3

First off, congrats on getting your navbar working and sticking with this over several days! 🎉🥂 There are a lot of things which could be improved, but at a glance the most glaring issue is that your styles are spread all across the HTML, CSS, and JS files. This makes it very difficult to reason about them. Here's how you could simplify the situation and ...


3

Your code looks fine. First, there isn't much going on so it would be a little too early to think about optimizations or all other sorts of things, unless you experience a real problem. But to make it more clear or simplify it, this is how I would recommend to do it: Cache HTML elements (selectors) into variables if you use them more than once. Don't repeat ...


3

Main Question Is there better logic? Repeated code The first thing that I see with this code, which perhaps you see also, is that it is quite repetitive - select a list of checkboxes to see if any are checked - if none are checked then show an error message and return, otherwise hide any affiliated error message. This violates the Don't Repeat Yourself ...


2

I've refactored your code below to add some of the repetitive items into functions and tried to improve your variable names a little. The new variable names and function names should clearly indicate their intended purpose/data. A rule of thumb worth remembering is the concept of DRY (Do not Repeat Yourself). const createArraywithJsonData = function(...


2

SELECT COUNT(DISTINCT comment_post_ID) FROM ".$wpdb->prefix."comments USE INDEX (left_frame_index) WHERE comment_approved = 1 AND comment_type = 'comment' LIMIT $count_limit Needs a better index; see the below. Do NOT compare a VARCHAR (such as comment_approved) with a numeric literal (such as 1), the index cannot be used....


2

Use the DOM API Always try to avoid adding HTML to the page. Modern browsers come with all the APIs and interfaces to create and manipulate page content. using he API's is much quicker than adding HTML, And as you will not need jQuery even faster still. Element by id If you have elements identified by their ids as follows... <label for="dlReleaseYear&...


2

I will briefly mention a few things I see in you're snippets. Is the code DRY enough? Given this line of code: pageUrl = $(location).attr('href'), pageBaseUrl = pageUrl.split('?')[0], searchStr = pageUrl.split('?')[1]; You would be better served using the parse_url function parse_url(string $url, int $component = -1): mixed $url = 'http:/...


2

A short review; You inlined the success function, I would use a properly named function outside of that block This $('#favoritepagesListBlock').empty(); $('#meetingsanddisclosuresBlock').empty(); $('#memberinstitutionBlock').empty(); $('#orderListBlock').empty(); can be $('#favoritepagesListBlock,#meetingsanddisclosuresBlock,#...


2

First, make your code work. orderShowMore = true is assigning true to orderShowMore - the code in the block after this is inevitably going to get executed. Just go if(orderShowMore). Second, don't use two variables named data - while scoping may make it unambiguous to the compiler, it's confusing to anyone reading your code. Also, consistent indenting goes ...


1

I have few hints save jQuery in $ variable: (function($) { // your code })(jQuery); $ is common for jQuery and it's easier to read because it shorter. Second and obvious is using loop to run calls in: if (selectedValues.length > 0) { selectedValues.forEach(function(value, i) { var num = i + 1; $(`input[name=gift_${num}]`)...


1

1. Is the code DRY enough? It could be less repetitive. The following lines appear in both _initPagination() and byauthor() if ($this->Static_model->get_static_data()['has_pager']) { $config['display_pages'] = FALSE; $config['first_link'] = FALSE; $config['last_link'] = FALSE; $config['prev_tag_open'] = '<li class="prev">'; $...


1

You can use bracket notation to reference the correct item depending on the content of input.TextField eg text: item[input.TextField.toLowerCase()] That way you only need test if input is a valid option. You can use an Array to hold the types and Array.includes to check if the item is in the array. Thus your code becomes switch (input.Type.toLowerCase()) { ...


1

Using CSS instead of JavaScript to apply styles If only there was browser support for :has() pseudo-selector - then the JavaScript function bringStickyInputToTopOfThePageOnMobile() could be eliminated. Another option would be to use :focus-within but additional selectors would need to be applied to limit the functionality to only the container(s) with an ...


1

Declarations Always declare variables that do not change as const rather than let or var For example the line let mostRecentAnswer = $('#summary').prev(), id = !mostRecentAnswer.length ? 1 : 1 + mostRecentAnswer.data('id'); Should start with const and if written using native API const id = Number(summary.previousSibling?.dataset.id ?? 0) + 1; ...


1

You can target all element ending with [id$='-Drawer-Shelf-Combo']. Use toggle to show/hide. $("[id$='-Drawer-Shelf-Combo']").on('change', function () { $(".under-drawer-bench").toggle(); }); Withtout the HTML/CSS I cant test it though.


1

The two first things that come to my mind: Using template strings Modifying the dropdown HTML once: $(document).ready(function () { $("#ddlReleaseYears").change(function () { var data = "[2021,2020,2019,2018,2017,2016]"; var arr = JSON.parse(data); $('#toptitle').text(arr[0]); var HTML = "" ...


1

Louys has already mentioned a couple great techniques. There are a few others: Use the shortcut method $.get() passing the URL as the first parameter and the success callback as the second parameter Do elements with the class "delCommentLink" get added to the page after the page is loaded or do they all exist when the page is loaded? If the latter ...


1

Yes there is a fair amount of repeated code - e.g. the options: dateFormat: "yy-mm-dd", timeFormat: "hh:mm TT", minuteGrid: 10, addSliderAccess: true, sliderAccessArgs: { touchonly: false }, These could be abstracted to a common object that gets extended with each call to ...


Only top voted, non community-wiki answers of a minimum length are eligible