Oscar LT
Oscar LT

Reputation: 797

Load attribute from external page

I have this:

$(document).ready(function () {
  $("#result").load("file.html *HERE*");
});

In HERE I want search only the elements with "fontsize:20pt". Is possible?

Thanks

Upvotes: 1

Views: 46

Answers (1)

mplungjan
mplungjan

Reputation: 178285

According to the specs

If there is a selector that can be created for your request, the answer is yes.

$("#result").load("file.html .pt20"); // if there's a class on the object

If not, you can extract the elements after if you have a way to identify them - note we need to use another ajax method - here $.getis used:

DEMO

$(function() {
  $.get("filept.html",function(data) {
     $(data).find("p").each(function() {
       var fs = $(this).css("font-size"); // note: "20pt" or 26.nnn for computed size
       if (parseInt($(this).css("font-size"),10) == 20) {
         $("#result").append($(this));
       }
     });
  });
});

Upvotes: 3

Related Questions