Sunday 15 July 2012

javascript - How to find a specified HTML element on a string -



javascript - How to find a specified HTML element on a string -

i trying "encapsulate" web phonegap app, finding problem. when create request server reply me html text, , want take html elements of text , append on div of index.html of application. create so:

jquery.get(rute, function(htmltemplate) { var info = jquery(htmltemplate).find('#wrapper'); //make little treatment data, not yet. jquery('body').html(data) });

i have other application similar:

function loadpage(placetoload, rute, callback) { jquery.get(rute, function(htmltemplate) { var info = jquery(htmltemplate).find('#wrapperapp').parent(); if(data.html()!==undefined) { placetoload.html(data); info = erasenoscriptexternalpages(data); info = erasestylesexternalpages(data); info = eraselinksexternalpages(data); makeimagescroll(data); } else placetoload.html(htmltemplate); if (callback!=undefined && typeof(callback)==typeof(function)) callback(); }); }

in sec case need differentiate between pages came external server (which must engineered not cause collateral damage), , local pages.

the case sec case works , first not!!! why!!??

i trying create simple test:

var html = '<head><style> body{background-color:rgba(128,128,128,0.3);}</style> </head> <body> <div id="test">hola</div> </body>'; jquery("#content").html(jquery(html).find("#test").html());

...but doesn´t work.

i want take specific element create little treatment (erase divs or aside section).

jquery(a).find(b) find b descendent of a. in example, #test root node, it's both , b, there no matches.

instead, can utilize .filter():

var html = '<head><style> body{background-color:rgba(128,128,128,0.3);}</style> </head> <body> <div id="test">hola</div> </body>'; jquery("#content").html(jquery(html).filter("#test").html());

http://jsfiddle.net/gg5r6mqp/

javascript jquery html

No comments:

Post a Comment