JQuery :: XPath Selectors To Replace Node Data
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
ADVERTISEMENT
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
View Related
Feb 20, 2010
I have the following javascript:
<script type="text/javascript">
$(document).ready(function(){
// autocomplete setup
[code]....
The autocomplete (I'm using this one) and the getJSON work perfectly. The problem comes when I try to do something with the returned json data. Line 14 won't work for me. Any selectors I try on the returned json data won't work. The selectors still work on items that were there before the json data was returned.
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
May 17, 2005
Consider the following XML doc returned to the xmlHttpRequest obj:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data>
<item id="1234">
<name>Test item 1</name>
<description>some text here</description>
</item>
<item id="1654">
<name>Test item 2</name>
<description>some text here</description>
</item>
</data>
How would I go about retreiving the item node's child element's data eg. "test item 1" ?
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 1, 2006
I'm working on something in jQuery with XPath
What I want to do is: if checkbox is checked, set background color od
label that contain input(checkbox) to red
I have this code:
$("label[input[@checked]]").css("background", "red");
but it doesn't working because of nested brackets [[ ]] and it freeze
the browser. In Xpath documentation say it can be used
any sugestions?
View 6 Replies
View Related
Jul 8, 2010
how can i have the functionality of load() except i want to append data instead of replace. maybe i can use get() instead but i want to just extract the #posts element from the loaded data
View 9 Replies
View Related
Aug 4, 2009
I have a bunch of divs with the same classname, 'mediafield':
And I have this jquery code in my header:
So I know that the click function is getting implemented.. The alert box appears however I get the following error in firebug: uncaught exception: Syntax error, unrecognized expression:[@class=mediafield] Line 0
Nothing happens when firebug is turned off... So I'm not sure why it's throwing the error.
View 5 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
May 19, 2009
Supposing I have the object reference to an object,how do I retrieve the xpath of a element.
View 3 Replies
View Related
Jan 28, 2010
How to consume web service in javascript...The output of the webservice is another XML file. I am new to XPath. how to use XPath to get the data out from the web service output, and show it in a simple table with 3 columns...
Here is the output from the web service:
Code:
View 4 Replies
View Related
Feb 21, 2007
Let's say you're getting some xml via ajax, instead of the ajax.responseText property you create a dom document using the responseXML property.
Is there a safe cross-browser way to query that document using xpath?
I know in IE you can use selectNodes/selectSingleNode, but what about other browsers?
View 3 Replies
View Related
May 11, 2010
However, I was wondering - I realize there does not seem to be a "standard" way to do this (without additional libraries), but is there any "hacky" method that can be used to get XPath support in IE? What I mean is for parsing the loaded HTML document.
View 1 Replies
View Related
May 21, 2010
How can i select immediate children of an element only. Like i have
<div class="widget">
<ul>
<li><a href="google.com">Google</a>
[code]....
View 1 Replies
View Related
Oct 12, 2009
Writing a sortable list function. My <li> elements contain several items (headings, paragraphs etc) and I want to add a class to the headings when they've been sorted. I have this code in my sortable init:
receive: function(event, ui) {
$(ui.item).addClass('editable');
},
This adds class="editable" to my newly-sorted <li> element - cool. What I want, though, is to add this class to the <h3> within my <li>. I tried:
receive: function(event, ui) {
$(ui.item + ' h3').addClass('editable');
},
but this just gave a syntax error.
View 3 Replies
View Related
Apr 23, 2009
I found that certain selectors work in all browsers except IE 8 and they need to modified. This selector pattern seem to work well in all browsers, including IE 8: jQuery("input[class='class_name'][type='text']") But this identical selector works in Firefox, Safari but not in IE 8: jQuery("input.class_name:text") In IE 8 it returns a "property not found" javascript runtime error. I don't know whether that the actual issue or if it is a side effect of some memory leak.
View 1 Replies
View Related
Apr 29, 2011
I'm trying to test if certain radio buttons are selected, but the name varies. My boss is considering changing the names to further isolate them breaking the script as it works now. I'm trying to figure out how to test the new case just like it works now. Here's a link to my pastebin
View 6 Replies
View Related
Nov 28, 2011
I am trying to assign a click event handler to any of the <a> elements in the code below:
<div data-role="content" id="picSpace" class="ui-content" role="main">
<div class="ui-grid-b" id="gamePics">
<div class="ui-block-a">
[code]....
View 5 Replies
View Related
Apr 4, 2009
Can I do this:
function showDiv(curEl){
hideDiv();
$(curEl).css("visibility","visible");
}
View 6 Replies
View Related
Apr 9, 2011
While trying to get a selector to work with ids that include square brackets, I searched the forum and found that I needed to escape the brackets with '\'. However, while this works with my fiddle: can't get the exact same selector to work within my page in either FF or Safari. I've triple-checked the id and it is correct; I know that jQuery is working on the page because changing the selector to$('.nameinput') gives the expected results. can't change the id because I'm working within an existing application; I know I could add a class to the input and use that as the selector instead. I'd prefer not to and would just like to figure out why this isn't working.
View 1 Replies
View Related
Feb 22, 2010
I have a page that has several embedded usercontrols with a popup reorderlist. Like
[Code]...
isthis the correct approach and if so what should the 'fld1' line look like to pull this data.
View 1 Replies
View Related
Jul 27, 2010
Is there a way to combine selectors with && condition. eg: $('.classname div[att=value]') Requirement is to select all div elements with class 'classname' and (&&)an attribute 'att' whose value is 'value'
View 2 Replies
View Related
Dec 30, 2010
What I'm trying to do is quite simple but as a beginner I'm getting incredibly frustrated with it. Here's my first attempt. I plan to do something a bit more fancy with the images, but I could see straight away that this wasn't the solution. Mouseover was changing the image before it had faded out and looked horrible. So, I thought I might put all the images in the same place and hide them, making them visible and bringing them to the front on mouseover of the corresponding hotspot.
[Code]...
View 6 Replies
View Related
Feb 18, 2010
I have the impression $('h1:after') e.g. doesn't work. How to manipulate these pseudo selectors with jQuery?
View 1 Replies
View Related