1

I am trying t display my text on screen. In this I am using one css to make color change.

Here is my code

var myStar =   '<span style="color: rgb(255, 0, 0);">*</span>'
myStr = "Hello"+ "<br>" + myStar+ '(myValue)';

But text is not appearing properly. Instead to display actual text it is displaying like this.

*</span>(myValue)" class="x-form-field x-form-text x-form-text-default x-form-textarea"  role="textbox" aria-hidden="false" aria-disabled="false" aria-readonly="false" aria-invalid="false" aria-multiline="true" aria-required="false" autocomplete="off">

It should only display

Hello

*(myValue)

Here is my actual js code where I am using this.

xtype: 'textArea',
height:70,
fieldLabel: '<div>'+myStr+'</div>',
name: myStr,
labelAlign: 'right',
margin:5,
labelWidth:180,
value: "some Value",

Can anyone suggest what I am missing here.

5
  • 1
    Can you share the entirety of the relevant javascript? The portion you've included in your question is just manipulating strings - it doesn't actually do anything regarding the <span>. We'll need a Minimal, Complete, Verifiable Example in order to help. Commented Jul 24, 2018 at 3:52
  • 3
    The section you've now added is still just an incomplete snippet of pseudo-code. Please refer to my link from the previous comment: How to create a Minimal, Complete, and Verifiable example. Commented Jul 24, 2018 at 3:55
  • i don't know what's your problem. but it works for me. Commented Jul 24, 2018 at 3:55
  • Are you sure you actually want to make use of two different variables (myStar and myStr)? And what is the actual problem you're facing -- you don't want the extra class / aria information there? Commented Jul 24, 2018 at 3:55
  • @ObsidianAge Actual problem is It should display only "Hello * Value" but instead of that it displaying what i mentioned in code. I actually have doubt for the div which i am using as a fieldLabel Commented Jul 24, 2018 at 3:58

1 Answer 1

1

I was able to produce the required result by using your code provided. Here is what I did.

In my HTML file, I created a div element with some id like this.

<div id = "someId">
</div>

Then I my JS file, I simply used your code to construct myStr.

var myStar =   '<span style="color: rgb(255, 0, 0);">*</span>'
myStr = "Hello"+ "<br>" + myStar+ '(myValue)';

and I fnally, I used HTML DOM innerHTML Property to set HTML content of that div.

document.getElementById("someId").innerHTML = myStr;

here is a working code.

var myStar =   '<span style="color: rgb(255, 0, 0);">*</span>'
myStr = "Hello"+ "<br>" + myStar+ '(myValue)';
document.getElementById("someId").innerHTML = myStr;
<div id = "someId">
</div>

Sign up to request clarification or add additional context in comments.

3 Comments

i think the DOM manipulation in this question is done using some js library, see question as some parameters are provided. No Doubt, your answer produces exact result, but it may not be helpful for the person in this case.
I think the same. Actually, the user had asked only what I gave an answer to initially. The person updated his question later.
oh ok, this definitely may help. Hope the person can achieve his solution through your correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.