简体   繁体   中英

how to get <td> value with span class 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?

$('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

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM