2014-10-30 5 views

답변

1

할 수 있습니다

//dom ready handler 
 
jQuery(function($) { 
 
    //click handler for the anchor element 
 
    $('.tags-group .cross').click(function() { 
 
    //find the `p` element of the anchor 
 
    var $p = $(this).parent(), 
 
     //read the p elements value attribute 
 
     value = $p.attr('value'), 
 
     //read the `p` element's text 
 
     text = $p.text(); 
 
    alert(value + ':' + text) 
 
    }) 
 
})
a.cross { 
 
    display: inline-blick; 
 
    line-height: 20px; 
 
    padding: 0 10px; 
 
    border: 1px solid red; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="tags-group inner-box"> 
 
    <p value="1">abc university 
 
    <a href="#" class="cross"></a> 
 
    </p> 
 
    <p value="2">xyz university 
 
    <a href="#" class="cross"></a> 
 
    </p> 
 
</div>

0
$(".inner-box .cross").click(function() 
{ 
    var paragrapthValue = $(this).parent().val(); 
} 
0

다음은 샘플입니다. http://jsfiddle.net/davidzapata/hqnur3k6/

$('.cross').click(function(evt){ 
    evt.preventDefault(); 
    var theP = $(this).closest('p'); 
    console.log('The P value:', theP.attr('value')); 
    console.log('The P text:', theP.text()); 
}); 
관련 문제