0

Can I use csquery to find a html with a certain attribute with a certain value.

So if I got a page where there is something like this

<html>
   <body>
      <div align="left">something</div>
   </body>
</html>

Can I then get the hole line out by search for a div with the attribute align with the value left? or even just the html element, and then get the value from within the attribute?

As always, thanks for the help and time.

DaCh
  • 921
  • 1
  • 14
  • 48
  • What are you actually attempting to do? I'm having difficulty understanding what your speaking about. – Greg Aug 17 '15 at 21:05
  • Sry Greg. i myself find it hard to explain. i want to get the value of the align attribute from the div tag element, within a html page using csquery. it's this better explained? – DaCh Aug 17 '15 at 21:14

1 Answers1

1

I haven't used csquery myself but when looking at the docs, and you can use css queries this should work

div[align='left']

EDIT: After being assured that this is in response to a client side operation, in the script it should look like this:

var rows = query["div[align='left']"];

This how you can look up elements by tag and attribute selectors, is to have the attributes you want in brackets. and then the value interpolated like so.

Daemedeor
  • 1,013
  • 10
  • 22
  • Hey Daemedeor. I don't see how i can get that from the CsQuery.CQ dom class.where did you find the docs you're ref to? I may be it's better than what i found myself. – DaCh Aug 17 '15 at 21:17
  • @DaCh i also just saw this SO question, might be more pertinent since i'm not sure if you're doing the lookup on the server or the client side: http://stackoverflow.com/questions/25665928/traverse-the-dom-with-csquery – Daemedeor Aug 17 '15 at 21:24
  • bear in mind, my selector is correct for what is being asked though – Daemedeor Aug 17 '15 at 21:24
  • Arhh sry. I'm doing the lookup client side. – DaCh Aug 17 '15 at 21:29
  • @DaCh i think my updated post should allow you some insight – Daemedeor Aug 17 '15 at 21:48