i have an array of control ids and this is how i retrieve them
var control = document.getElementById(arrVarIDToControlID[variable_id]);
for the text boxes am able to append the node to the parent node(textbox) but for the text area am not able to append the node to the parent(textarea) but it adds the node to the page instead
control.parentNode.appendChild("text");
i use the above code to append. how can i be able to append to the textarea but not the page??
Have you tried:
$('#'+arrVarIDToControlID[variable_id]).parent().append('<div>text</div>');
You can try to append the text only but I recommend to always use a container
Try using insertAfter() on the TextArea control.
$(arrVarIDToControlID[variable_id]).insertAfter("text");
Related
Bellow is my elements:
I already know how can I find the id='0' using:
.waitForElementVisible("//form[contains(#id, '0')]").
My current problem is how to identify "Excelente Contribuição in "<form". I need to click on text Excelente contruibuição.
I try to use this one to identify the element first, but don't work:
.waitForElementVisible("//form[contains(#id, '0') and contains(text()='Excelente contribuição')]")
Bellow is the button I need to click.
Try to use this XPath to match form by #id and div by label text:
//form[#id='0']//div[label[normalize-space()='Excelente contribuição']]
I need to replace each word in the textarea by a span with unique id. I need the code in JavaScript. I have tried creating a DOM element and inserting it in text area using the following code.
var s = document.createElement('span');
var text=document.createTextNode("inside tag");
s.appendChild(text);
document.getElementById("t1").appendChild(s);
t1 is the is the id of my text area. The above code isn't giving any result.
Also, I tried another method:
document.getElementById("t1").innerHTML="<span>inside tag</span>";
innerHTML isn't working here.
What do I do?
It has to be the value property instead of the innerHtml because of the fact that value property is used for setting the value for input/form elements. innerHTML on the other hand is normally used for div, span, td and similar elements.
So as you are using a textarea you shall go with value property.
document.getElementById("t1").value = "Whatever the text/html you want to insert here";
To change your value of text arena, you will have to do this:
document.getElementById('t1').value = '<span>inside tag</span>';
I know how to get element in jquery by id or class or by using find but I have an element like the following and I want to find it and change the text inside(here is test):
<text x="524" text-anchor="end" zIndex="8" style="cursor:pointer;color:#909090;font-size:9px;fill:#909090;" y="170">test</text>
but the problem is that here this text element does not have any id and I have so many text element in the html file so is there anyway that I can access just this text element(I also can not add id to this text because is created by plugin) ?
To select elements based on content, use $(":contains('text')")
See: http://api.jquery.com/contains-selector/
Ans then you can edit the text like this.
$("text:contains('theTextYouKnowIsInside')").html("newText");
You could access via any of following methods :
$("text[x=524]").html("here is test");
$("text[x=524][y=170]").html("here is test");
$("text[y=170]").html("here is test");
here is the demo JsFiddle
What is the right way to update text of a element with minifiedjs?
E.g.
<a class="myRef">Old text</a>
I have tried logical:
$('.myRef').text('New text');
But it doesn't work.
http://minifiedjs.com/docs/howto.html#html_text
$('.myRef').fill("My new text");
I get it right from documentation.
You can use the fill method to replace the existing text value.
$('.myRef').fill("New Text Value");
or you can use the add method to append text to the existing text.
$('.myRef').add("Append Text");
(The text method returns the concatenated text content of all nodes in the list.)
This list of How To's is helpful for learning how to use minifiedjs.
I am appending the text to the div like
span.insertBefore("#text");
here span represents the text that is appending. How can i get the text on any other event like button click etc.
You need to use text() function of jquery element using selector
txt = $("#text").text(); //id selector
txt = $('.classOfElement').text() //class selector
You can also get the text by using javascript like:
var text = document.getElementById('#text').innerHtml();