1

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

1
  • 1
    Not directly, no. You can only select by CSS rules (eg id, class, attribute etc). You would need to grab all the whole page and filter() the elements to find those with the matching font-size set. Alternatively if you know the elements you want, add a class to them and use that class to target them. Commented Jul 13, 2015 at 8:43

1 Answer 1

3

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));
       }
     });
  });
});
Sign up to request clarification or add additional context in comments.

9 Comments

load() will still append all the content. Should use other ajax method, e.g $.get()
It will always load all the content and then filter on the selector. If you do not want that, you need a proxy to read the file and extract
I was talking about the second method, not using selector
If i Use this, console.log find a wrong in the 4th line: Unexpected token }
I missed a quote (thanks for the edit) and added brackets for you
|

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.