Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:00:17+00:00 2026-05-29T06:00:17+00:00

I am having fun with jquery, and wonder if you can help make my

  • 0

I am having fun with jquery, and wonder if you can help make my code more efficient. Below is the only working code I can do so far. Any other trial is not happy:

HTML

<div class="someparent">...<p><input type="text"  value="0 0 12 12" class="radius"></p></div>

JQUERY:

    $('input.radius').each(function() {
            var preview = $(this).parents('.someparent');   

            $(this).keyup(function() {
                var rad = $(this).val();

                c = rad.split(' ');
                tl = c[0] ? c[0] + 'px' : '';
                tr = c[1] ? c[1] + 'px' : '';
                bl = c[2] ? c[2] + 'px' : '';
                br = c[3] ? c[3] + 'px' : '';

                var radius = tl + ' ' +  tr + ' ' + bl + ' ' + br;              
                $(preview).css('border-radius', radius);
            });
            if ($(this).val()) {
                var rad = $(this).val();

                c = rad.split(' ');
                tl = c[0] ? c[0] + 'px' : '';
                tr = c[1] ? c[1] + 'px' : '';
                bl = c[2] ? c[2] + 'px' : '';
                br = c[3] ? c[3] + 'px' : '';

                var radius = tl + ' ' +  tr + ' ' + bl + ' ' + br;                  
                preview.css('border-radius', radius);
            }
     });

Basically the code wants to update dynamically the properties based on any input, while keeping its current state whenever available as default.
Thanks for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:00:19+00:00Added an answer on May 29, 2026 at 6:00 am

    if values always initial without pixel, simply use:

    $('input.radius').each(function() {
        var preview = $(this).parents('.someparent'); 
    
        $(this).keyup(function() {
            var rad = $(this).val();
            c = rad.split(' ').join('px ');
            $(preview).css('border-radius', c);
        }).keyup(); // trigger keyup manually to initial
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having fun working with System.Threading.Tasks . Many of the code samples I
I always seem to be having fun working with the Ax 2009 product until
I'm pretty new to JQuery and JQuery-UI, but I'm having fun with it so
I'm having fun with Razor today! Can you see what is wrong with this
I'm just starting with having fun with Spring Roo... Everything is nice so far.
I am somewhat new to jQuery but have been having fun trying learn about
Having some fun with t-sql and sp_executesql (test output below). The last piece of
I'm having fun with a change to a content type field (from a node
I'm playing with Google Go and I'm having fun (!), but I'm having some
I am beginning some experimentation in writing a kernel and having fun doing it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.