Jquery: How do I query from a given html element?


var x = $("#divid")[0];
$(x).find("data"); //look for an element

jquery find seem to disturb inner html!

Search for: jquery find seem to disturb inner html!

Or may be ie is the culprit!


function akcExpand_folderWidget_function(divObject)
{
    alert("ok i got called");
    var x = $(divObject).find("folder_id")[0];
    alert(x.childNodes.length);
    alert(x.nodeName);
    alert($(x).html());
}

<div class="akc_expand" type="folderWidget">
    <data x="10">
        <folder_id x="15">231</folder_id>
    </data>
    <div class="akc_expand_result">
    </div>
</div>

In ie the innerhtml has gone 'ghaayab!' (Disappear)

How to create a DOM from string in javascript?

Search for: How to create a DOM from string in javascript?

how to create XML DOM using ie from a string in javascript?

Search for: how to create XML DOM using ie from a string in javascript?

jquery DOMPareser ie XML

Search for: jquery DOMPareser ie XML

See if this blog about jquery parsexml method helps

Search for: See if this blog about jquery parsexml method helps

jquery parsexml usage

Search for: jquery parsexml usage

Here is jquery's document on parsexml

jquery parsexml throwing an exception

Search for: jquery parsexml throwing an exception

ie eating away removing quotes in innerhtml

Search for: ie eating away removing quotes in innerhtml

Lo, it is true. Here is SOF


A jquery selector returns an array of DOM elements
It is always an array of DOM elements
so you have to access element 0
this element is a base DOM and not a jquery object
you have to wrap it with a $ if you want to further search
The find will also return an array of DOM elements
ie has a problem obtaining inner html for some of these elements
you can use $.parseXML to parse arbitrary xml data
However if the input to this process is an inner html
   then ie has problems
ie seem to remove the quotes from the attributes of inner html
which means this inner html will not get parsed as 
   the attributes are without quotes which is not valid xml
There are suggestions to use tools like "tiny html"
   to format the inner html to requote them
If your html doesnt start out as an inner html you are ok

<div class="akc_expand" type="folderWidget">
    <data>
        <folder_id>231</folder_id>
    </data>
</div>

function akcExpand_folderWidget_function(divObject)
{
    alert("ok i got called");
    var y = $(divObject).find("data")[0];
    alert($(y).html());
}

This code will not work in ie but will in chrome. So there is something odd ie is doing here.


<div class="akc_expand" type="folderWidget">
   <div>
        <p class="x">ddddd</p>
   </div>
</div>

it appears ie ignores the non-html tags and doesn't know how to reconstruct!