0

I create a variable where I load an html document into it: result = data;

How would I get the item elements from the result: $(result+ " item"); -> which doesn't work.

I want to be able to do something like this

$("#result_html item"); -> but with result not #result_html
1
  • ill add the pont when i can..there is a timer Commented Nov 14, 2011 at 20:16

5 Answers 5

2

If I understand:

$(result).find('item');
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming I've understood your question correctly, you want to select elements from the loaded document. To do so, you can pass the variable containing the document into jQuery as a context:

var item = $("#result_html item", result);

You could also find the element:

var item = $(result).find("#result_html item");

1 Comment

No problem, glad I could be of help :)
0

If I understand you correctly:

$("#" + result + "_html item");

Comments

0

You can do it:

var resultDivId = 'result';
var $result = $('#'+resultDivId);
// find:
$('items', $result);

Comments

0

You can load or retrieve data from anywhere id-ed with jQuery.

If the content is HTML code, you would use the .html:

$('#wherever').html('your html (<p></p><div></div>, etc, goes here and will show in "wherever"');
to retrieve it, variable = $('#wherever').html();

If the content is pure text, like a result of some kind of concatenation or math, you could use plain .text:

$('#wherever').text('This text goes into "wherever"'); or
$('#wherever').text(2+2+4+5);

to retrieve it, variable = $('#wherever').text(); or
variable = $('#wherever').text()+55;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.