JQuery :: Replace Text In A Node?
May 18, 2009
I've recently moved over from Protoype and was used to using the update() function to replace text within a node - something like
this:
PROTOTYPE
<p id='dText'>text to be replaced
$('dText').update('New text string')
[code]....
Now it appears to me that in jQuery, there isn't an out of the box function to replace the contents of a node without also replacing the
node too, hence the reason I am chaining remove() and append().
View 4 Replies
ADVERTISEMENT
May 25, 2009
I'm using a simple dom parser function to catch xpath information of all nodes of a document. Say html is like :
HTML Code:
<div>
<div>Everyday People</div>
<div>My name is ACE</div>
<div>Hello world</div>
</div>
And parsing the DOM to store the xpath infor in array 'arr'
Code:
<script type="text/javascript" src="js/jquery/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery/js/xpath-selector.js"></script>
<script type="text/javascript">
function get_XPath(elt)
{var path = '';
for (; elt && elt.nodeType==1; elt=elt.parentNode)
{var idx=$(elt.parentNode).children(elt.tagName).index(elt)+1;
idx>1 ? (idx='['+idx+']') : (idx='');
path='/'+elt.tagName.toLowerCase()+idx+path;
}return path;
}var arr = Array();
htmlDoc=document;
x=htmlDoc.documentElement.childNodes;
for (i=0;i<x.length;i++){
arr.push(get_XPath(x[i]));
}
</script>
And later on in the script using the values stored in 'arr' to perform some functions like showing,hiding or changing content of nodes.
Code:
<script>
for(i=0;i<arr.length;i++){
//catch the object reference with the xpath info
$(arr[i])
}
</script>
But in the snippet above,I'm getting a object but unable to I'm unable to get the object reference..and use it for something like
$(arr[i]).text();
Any work on Jquery Xpath selectors?
View 1 Replies
View Related
Dec 18, 2006
I have a question about manipulating a document. Suppose for example
that I had a table like this:
<table>
<tr id="row1">
<td>R1C1</td>
</tr>
<tr>
<td>R2C1</td>
</tr>
</table>
What I want to do is add an onclick event handler to row1 to insert a
row after row1. I can't seem to find a way to do it though. After
creating the new row node, I could try something like
document.getElementById("row1").parentNode.appendChild(newNode) but
that would add the new row to the bottom of the table. The
insertBefore() method is the right idea but I want to insert the new
row AFTER row1 and there doesn't seem to be an insertAfter() method.
I thought about navigating through the DOM tree to get the row after
row1 and then using insertBefore() but the table is generated
dynamically and there won't necessarily be a next row.
View 18 Replies
View Related
Jan 17, 2007
I'm struggling with Javascript and the DOM. Can anyone help me with
the appropriate script to get the SVG <g> element and loop through the
<text> elements, changing the value of each "y" attribute as I go.
The relevant fragment is shown below.
<g id="yaxisGroup" transform="translate(0,0.00) scale(1,1.00)">
<text x="0.00" y="24.00" font-size="18">Dog</text>
<text x="0.00" y="54.00" font-size="18">Cat</text>
<text x="0.00" y="84.00" font-size="18">Horse</text>
<text x="0.00" y="114.00" font-size="18">Bird</text>
</g>
View 9 Replies
View Related
Nov 16, 2009
<h1>November<span>2009</span></h1>
making a variable equal the h1 html() without the span text.
// equals 'November2009'
var monthDelete = $('h1').html();
// I need just 'November'
View 1 Replies
View Related
Jun 24, 2010
So I have the following xml:<ingredient name="rice"><us>1 cup</us><metric>250 mL</metric> of uncooked Korean rice</ingredient>
I want grab only the "of uncooked Korean rice" part. I tried to use text() but it would grab the text from inside the "us" and "metric" element.
View 9 Replies
View Related
Nov 22, 2011
I am trying to append to a text node(which is contained in another element) a string but i canot. Here is the code-tell me please where is the error below because i cannot spot it.The containing element is a div class with name calendar, as you can see. Inside the calendar the current month is displayed(not shown here-which i get with the date object), i want to append to the month the test p.
$('.calendar:eq(0)').contents().filter(function()
{
return this.nodeType == 3;
}).append('<p>Test</p>');
View 2 Replies
View Related
Mar 17, 2010
I'm trying to re-export a filtered set of XML data. For an input like this:
<object>
<header />
<thing1>
<value1>1</value1>
[Code].....
However, this currently returns 'undefined'. Is there any easy way to do this, or do I need to actually parse the XML below thing1 and manually write my own XML sub-tree?
Jquery 1.4, Firefox
View 1 Replies
View Related
Jul 30, 2010
let's say I have this code markup:
<div id="id1">
This is some text
<div class="class1"><p>lala</p> Some markup</div>
</div>
What I would want is only the text "This is some text" without the child element's .class1 contents.
How would I do that? A normal selector would select "recursively", so how do I limit it to one level?
View 4 Replies
View Related
Mar 24, 2011
Say I have the following HTML:
Code:
<h1> 45 <em>people like this</em></h1>
How do I select just the '45' portion?
View 1 Replies
View Related
Dec 7, 2011
I have a small question. I am building an AJAX-based content editor and in one portion the following xml tag needs to be processed:<
[Code]...
View 1 Replies
View Related
Jun 7, 2010
I'm trying to output the text value from a list node. why it's not working. How do i tell how many childNodes are in the ul element?
Code:
function test(){
var x = document.getElementById("test");
alert(x.firstChild.nodeValue);
[Code].....
View 1 Replies
View Related
Feb 27, 2009
I'm trying to add the text value of an xml element to a variable but the closest i can get is having the variable set to [text object] using this method:
rootNode.getElementsByTagName('instructions')[0].childNodes[0];
I have also tried these methods but they always return undefined:
rootNode.getElementsByTagName('instructions')[0].childNodes[0].text;
[code].....
View 1 Replies
View Related
Feb 28, 2011
am trying to iterate out the values of an xml file. I have got the file to load though I have not yet been able to extract the values. code...
View 2 Replies
View Related
Nov 18, 2006
trying to read text from text child, basicaly seeking for equvivalent for this:
var groupArray = secondElement.getElementsByTagName("DIV");
// so looking for text nodes
var groupArray = secondElement.getElementsByTagName("??????");
hmm tryed this, seems DOM doesn't see the text node that itself created
// 1.CREATING & filling
imgElement = document.createElement("IMG");
imgElement.src = arrElementsImages[i];
imgElement.setAttribute("style","float:left");
imgElement.style.styleFloat = "left";
firstElement.appendChild(imgElement);
firstElement.appendChild(document.createTextNode("u00a0" + "a"));
//2.TRANSFERING ALL CHILDS TO secondElement
// case1 --> ONLY IMAGE APPEARS !!??
for (i = 0; i < firstElement.childNodes.length; i++)
{
secondElement.appendChild(firstElement.childNodes[i]);
}
//case2 --> TEXT AND IMAGE APEARS
secondElement.innerHTML = firstElement.innerHTML;
View 3 Replies
View Related
Feb 27, 2011
I am trying to iterate out the values of an xml file. I have got the file to load though I have not yet been able to extract the values.Considering that theXml is an xml file and 'coords' are tags containing a coordinate how would I extract the value. Here is the code I am using
Code:
var coordTags = theXml.getElementsByTagName( 'coords' );
var len =coordTags.length;///this works
[code].....
View 1 Replies
View Related
Dec 3, 2005
var lbl=document.createElement('LABEL');
var txt=document.createTextNode('text');
lbl.appendChild(txt);
in above txt node i want a space infront of that
i tried below, but no use
var txt=document.createTextNode(' text');
any idea ???
View 3 Replies
View Related
Aug 29, 2009
I've worked out how to get the value from a select option tag, but can't work out how to get the text inside the option tags. Here is the code I am using to get the value attribute from the option tag..
[Code]...
View 2 Replies
View Related
Sep 12, 2011
I'm trying to read a text file with node.js. This text file is a line of just numbers. I add every line to an array as a string. What I want to do is make it so every element in the array is only one number in the text file. When I use the split function with (" ") it doesn't work correctly; it prints out a string as all the numbers in the text file. how would I delimit this text file with every space or new line.
var fs = require('fs');
var array = fs.readFileSync("10_01.txt").toString().split(" ");
for (var ind = 0; ind<array.length; ind++)
[code]....
Is there a better way to do this because at the moment it doesn't seem to display what I want?
View 3 Replies
View Related
Oct 21, 2010
I have an AJAX application using which im attempting to acces a #Text node in the NAME tag of a XML document. i then want to sort the names and place them into tables <td> tag. i can put the names in the <td> but i want them sorted alphabetically. from my understanding im suppose to be able to sort an array simply like this Array[].sort();..............this is the reason i need the text to be an array. Unless you know a simpler way to do this.
Code:
function postNames(){
var signersdoc = xmlHttp.responseXML;
var container = document.getElementsByTagName("td");
[code]....
View 2 Replies
View Related
Nov 4, 2009
Code:
<a href="#" onclick="showDistributors('city0','raccoon0','national0',pass link text as variable into the function "showDistributors"); alert(this.text()); return false;">St Albans</a>
How do I pass the distributor name into the function as a variable? I am having trouble finding useful information on "this" method
View 2 Replies
View Related
Nov 23, 2009
I'm using jsTree-0.9.9a. As a test this is the code i'm using to display the ID
oncreate: function(NODE, REF_NODE, TYPE, TREE_OBJ, RB)
{
if (TYPE === "inside") {
parent_id = $(REF_NODE).attr('id');
alert(parent_id)
}}
This works fine when the parent has no child nodes, however, when a child node exists nothing is returned.
View 1 Replies
View Related
Oct 9, 2005
After much work, I've come up with some Javascript/DOM that almost works :)
function setblocktitle(id, text)
{
document.getElementById(id).firstChild.nodeValue = text;
}
With my HTML being:
<div id="hits" class="modules">
<h2>Hits</h2>
<div class="blah">
...
The problem is, when calling setblocktitle with setblocktitle("hits", "Totals"); I end up with the attached image rather than "Hits" being replaced by "Totals".
View 2 Replies
View Related
Oct 15, 2010
How can I search and replace Text with jQuery? I'm new to Jquery and Javascript.
View 2 Replies
View Related
Jun 12, 2009
I'm redesigning my website at the moment and am looking todo things a little more efficiently this time around.Currently, I have something that looks like this like this:HEADING NUMBER ONEimage oneimage twoimage threeHEADING NUMBER TWOimage fourimage fiveimage sixWhen someone hovers over image one, the actual text of "HEADING NUMBERONE" changes to "IMAGE ONE IS COOL," and reverts when their cursorpasses out of the image.When someone hovers over image five, the actual text of "HEADINGNUMBER TWO" changes to "IMAGE FIVE IS THE COOLEST," and reverts whentheir cursor passes out of the image.The "images" in question will actually be used to manipulate aGalleriffic 1.0 slideshow, built on jQuery, so I'd love to find anice, efficient way to do this, also using jQuery.
View 1 Replies
View Related
Sep 22, 2011
I want to replace all text in the html that contains the word "Hello" to "Hi" (quotes not included and not case-sensitive). Here's what I've made:
if ($('body:contains("Hello")').length > 0) {
$("*").each(function () {
$('body').html($('body').html().replace('Hello','Hi'));
});}
Without the:
$("*").each(function () {
It only searches for the first word so I added the line above to search within all elements (If this is correct). But the problem is, I notice that the line I added seems to cause the page to run slower than usual. Is there any other way to do this?
View 6 Replies
View Related