Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery- get different page elements

I want to get element attribute value which belongs to other html page.

For example if I am in file a.html and want to get data like element attribute value from b.html in a.html

All I am trying to do in jquery.

Please suggest!

I read posts but I want like below-

something like->
[Code of a.html]

var result = get(b.html).getTag(img).getAttribute(src)//not getting exactly
$("#id").append(result)

any idea how can i achieve this?

like image 229
S Singh Avatar asked Sep 27 '11 09:09

S Singh


People also ask

How will you select all the div elements on the page using jQuery?

The jQuery syntax is a little simpler, but not much more: $("div") is the jQuery equivalent to document. getElementsByTagName("div") . Here is the API documentation on jQuery's element selector: “Description: Selects all elements with the given tag name.

What does the jQuery wrap () function do?

jQuery wrap() method is used to wrap specified HTML elements around each selected element. The wrap () function can accept any string or object that could be passed through the $() factory function. Syntax: $(selector).

Can we use multiple selectors in jQuery?

You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.


1 Answers

first you will have to fetch the b.html and then you can find the attribute value e.g.

//if you dont want to display the data make the div hidden
      ^
$("#someDivID").load("b.html",function(data){

var value=$(data).find("#elementID").attr("attributeName");
});
like image 52
Rafay Avatar answered Sep 17 '22 22:09

Rafay