最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to get <td> value with span class in jquery - Stack Overflow

programmeradmin1浏览0评论

My table is

<table id="ResumeWrite" class="Vasprice" cellpadding="0" cellspacing="0" border="0" width="100%">
 <tr>
       <th width="20%" class="bdrL_blue valignT highlight">
       <span class="font18">0 to 1 year Experience</span>
       </th>

       <th>
        <input type="button" value="submit"/>
       </th>
</tr>

i want to alert the value 0 to 1 year Experience when i click the button. how to do in jquery?

My table is

<table id="ResumeWrite" class="Vasprice" cellpadding="0" cellspacing="0" border="0" width="100%">
 <tr>
       <th width="20%" class="bdrL_blue valignT highlight">
       <span class="font18">0 to 1 year Experience</span>
       </th>

       <th>
        <input type="button" value="submit"/>
       </th>
</tr>

i want to alert the value 0 to 1 year Experience when i click the button. how to do in jquery?

Share Improve this question asked Nov 14, 2013 at 10:04 PoliDevPoliDev 1,4789 gold badges25 silver badges46 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 1

You can do this by many ways. I think most simple is:

$(".font18").text();
$(".font18").html();

or

$("#ResumeWrite span.font18").text();

Last string only improves the accuracy of the finding desired item.

$('input[type="button"]')click(function(e){
e.preventDefault();

alert($(".bdrL_blue").text());
});

and you can do by also following way

   $('input[type="button"]').click(function(e){
    e.preventDefault();
        $(this).closest('tr').find('span').text();
       //or
      $(this).closest('tr').find('th').text();
    });

see DEMO by all THREE WAYS

Try this:

$('input[type="button"]').click(function() {
    var text = $(this).closest('tr').find('span').text();
    alert(text);
});

Note, I didn't use the classes on the element to select it as they appear to be style classes, and not semantically linked to the content of the element.

Example fiddle

$('#ResumeWrite input[type="button"]').click(function(){
    alert($(this).parent().prev().find('span').text())
})

Demo: Fiddle

alert($(".font18").text());

or alert($("#resumeWrite .highlight span").text()); You should read the jquery doc, and follow some tutorial, it's very basic...

发布评论

评论列表(0)

  1. 暂无评论