In jQuery you can do :
$("a[href$='.img']").each(function(index) {
alert($(this).attr('href'));
}
I want to write a jQuery function which crawls x-levels from a website and collects all hrefs to gif images.
So when I use the the get function to retrieve another page,
$.get(href, function(data) {
});
I want to be able to do something like
data.$("a[href$='.img']").each(function(index) {
});
Is this possible ?
...UPDATE...
Thanks to the answers, I was able to fix this problem.
function FetchPage(href) {
$.ajax({
url: href,
async: false,
cache: false,
success: function(html){
$("#__tmp__").append("<page><name>" + href + "</name><content>" + html + "</content></page>");
}
});
}
See this zip file for an example how to use it.
Pure JavaScript can be faster for DOM selection/manipulation than jQuery as JavaScript is directly processed by the browser. jQuery has to be converted into JavaScript to make it run in a browser. All these can be done in JavaScript but we may have to write many lines of code.
Projects In JavaScript & JQueryYes, it is possible to pass a variable into a jQuery attribute-contains selector. The [attribute*=value] selector is used to select each element with a specific attribute and a value containing a string.
If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object. var myDomElement = document. getElementById( "foo" ); // A plain DOM element.
A jQuery object is a Javascript object, which may or may not have anything to do with the DOM (usually it does). A jQuery object is a convenience wrapper around a DOM element in Javascript which is a method to manipulate the DOM which is a representation of the page which was created from an HTML file.
you could put recived data into the DOM and then run
$("a[href$='.img']").each(function(index) {
alert($(this).attr('href'));
}
something like this
$.get(href, function(data) {
$("#somelement").hide();
$("#somelement").html(data);
$("#somelement").find("a[href$='.img']").each(function(index) {
alert($(this).attr('href'));
}
$("#somelement").show();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With