user3432257
user3432257

Reputation: 415

jquery select with the child is not working

I have this html

<div id="surname">
<span>Name</span>
</div>

I want to get the Name

My Jquery

 $('#copySurName').zclip({
            path: 'js/ZeroClipboard.swf',
            copy: $("surname span").html();

pleas see the #surname span

but I got empty results

Upvotes: 0

Views: 69

Answers (5)

Yasitha
Yasitha

Reputation: 2303

Id selection (#) is missing in your Jquery code. Should be $("#surname span").html()

Demo

$(function() { // on page load
  $('#copySurName').zclip({
    path: "http://www.steamdev.com/zclip/js/ZeroClipboard.swf",
    copy: $("#surname span").html()
  });
});

Upvotes: 4

Kiranramchandran
Kiranramchandran

Reputation: 2094

If You are Using ID as your jquery selector , please prefix #

You Can Try This

$("#surname span").html();

Or

$("div#surname span").html();

Upvotes: 1

Chetan Gawai
Chetan Gawai

Reputation: 2401

Try this

alert($("#surname span").text());

Upvotes: 1

Pratik Joshi
Pratik Joshi

Reputation: 11693

Use

 $('#copySurName').zclip({
            path: 'js/ZeroClipboard.swf',
            copy: $("#surname > span").html();

Upvotes: 1

RGS
RGS

Reputation: 5211

$('#copySurName').zclip({
       path: 'js/ZeroClipboard.swf',
       copy: $("#surname").find("span").html();
});

Upvotes: 1

Related Questions