Ideally, in jQuery's style: $ele.prop('tagName')
You can do $ele[0].name
That's what I am doing right now. But, I am working on a project where the code is executed both on the server side and in the browser, and doing $ele[0].name does not work in the browser. An alternative approach would be the availability of a .get() method, so I can do $ele.get(0).name on both the client and server side.
Right now I am using feature detection to deal with both environments.
I think you could just do….
Browser:
$ele[0].tagName
Cheerio:
$ele[0].name
On Apr 7, 2013, at 10:38 PM, Kishore Nallan [email protected] wrote:
That's what I am doing right now. But, I am working on a project where the code is executed both on the server side and in the browser, and doing $ele[0].name does not work in the browser. An alternative approach would be the availability of a .get() method, so I can do $ele.get(0).name on both the client and server side.
Right now I am using feature detection to deal with both environments.
—
Reply to this email directly or view it on GitHub.
Thanks - yes, that indeed works. This issue is more about maintaining consistency with jQuery's API.
tagName is DOM-specific. Cheerio's internal structure has nothing to do with the DOM. If you're looking for something that emulates the DOM, I would take a look at jQuery + JSDOM.
On Apr 7, 2013, at 10:43 PM, Kishore Nallan [email protected] wrote:
Thanks - yes, that indeed works. This issue is more about maintaining consistency with jQuery's API.
—
Reply to this email directly or view it on GitHub.
You could try doing something like...
var tagName = elem[0].tagName || elem[0].name;
Should work in browser & server.
Most helpful comment
You could try doing something like...
Should work in browser & server.