Coder Social home page Coder Social logo

Comments (4)

lukasberns avatar lukasberns commented on September 24, 2024

You can do [myElement valueForKey:@"innerHTML"] or if you want to do it neatly, you might be able to define a protocol with a -(NSString*)innerHTML; method and cast the GAScriptObject to it. Then you can probably use myElement.innerHTML (without actually coding anything)

from gajavascript.

lukasberns avatar lukasberns commented on September 24, 2024

Apart from that I think you should ask this question on a site like StackOverflow since this is not an "issue"

from gajavascript.

newyankeecodeshop avatar newyankeecodeshop commented on September 24, 2024

In your code snippet above, [document getElementsByClassName:@"div"] would return an HTML collection of elements, so you'll have to do something like this:

#import "GAScriptMethodSignatures.h"  // for "[length]" and "[item:]"

id document = [webView documentJS];
id myElements = [document getElementsByTagName(@"div")];

for (NSInteger i = 0; i < [myElements length]; ++i)
{
    id anElement = [myElements item:i];
    NSString *innerHTML = [anElement valueForKey:@"innerHTML"];
} 

If you want to get all the DIVs filtering by an attribute, you can use [document querySelectorAll:@"div[attr=val]"]. Make sure to try out the query in the Safari Web Inspector first, since it might take some tweaks to get what you want. "querySelectorAll" is really handy and gives jQuery-like access to elements in a single method call.

from gajavascript.

newyankeecodeshop avatar newyankeecodeshop commented on September 24, 2024

Experimenting with this code helped me find a bug in the NSFastEnumeration implementation inside GAScriptObject. Cool.

from gajavascript.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.