simple user
simple user

Reputation: 383

How to get span id from innerHTML

My need is very simple and I am not getting any way yet. I have JQuery object 'node' which contains div id. When I write below code:-

alert($(node).get(0).innerHTML)

I get result as following:-

<div><span id="spn_148">ABC</span></div>

I only want to get span id i.e "spn_148" from innerHTML of $(node). Please help me out

Upvotes: 1

Views: 881

Answers (1)

dfsq
dfsq

Reputation: 193261

You can get span id like this:

$(node).find('span')[0].id

Bracket [0] is the equivalent to .get(0) in your example, just shorter. So the idea is to find span element withing node and get its id property.

Upvotes: 2

Related Questions