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 8500685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:00:44+00:00 2026-06-11T01:00:44+00:00

How i can replace the width in below code with a variable value? $(‘<div/>’,

  • 0

How i can replace the width in below code with a variable value?

$('<div/>', {
  'class': "formErrorContent",
   width: '13px',
   text: promptText
}).appendTo(prompt);

Like

 var promptWidth = (promptText.length * 5) - (promptText.length/2);
 var promtWidthString  = promptWidth + 'px;'
 var promptContent = $('<div/>', { 'class': "formErrorContent", style: 'width:' +   promtWidthString , text: promptText}).appendTo(prompt);

The above code will end up in a extra

< /br >

at end of the promtText

  • 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-06-11T01:00:46+00:00Added an answer on June 11, 2026 at 1:00 am

    As you are using appendTo there is no need to store the object in a variable. you can use width for setting width style to the element, also remove the + from your code, note that if you are adding markup, instead of text, you should use html.

    $('<div/>', { 
        'class': "formErrorContent", 
         width: promtWidthString,
         html: promptText
    }).appendTo(prompt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I replace the maxlength attribute with something in CSS? <input type='text' id=phone_extension maxlength=4
I have this code: <div id=container style=width: 800px; height:300px; margin: 0 auto;overflow:hidden;></div> I need
Does anyone know how can I replace the passing variable in html with Javascript?
I'm rendering a prototype using below code: {{form_widget(form.get('prototype').myField, {'attr': {'value': '<%= myModelProperty %>'} })
In my example code below i would like to replace the item in the
This is my code below and I am trying to pass the ID variable
How can eregi() function can be replaced here with preg_match() function in below given
How can replace arabic number with latin number as that doesn't change number into
How can I replace characters with preg_replace , that are enclosed in quotes? I
How can I replace CHAR with VARCHAR2 in all tables in a schema? Note:

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.