Question: How to get specific value from many <p>

Question

How to get specific value from many <p>

Answers 2
Added at 2016-12-31 10:12
Tags
Question

I have make a list with query result with Laravel. The code is :

            @foreach(array_chunk($result->all(), 3) as $row)
                <div class="row">
                    @foreach($row as $r)
                        <article class="post col-md-4 col-sm-6 col-xs-12">
                            <div class="post-inner">
                                <div class="content">
                                    <h3 class="post-title">{!! $r->original_name !!}</h3>
                                    <div class="meta">
                                        <ul class="meta-list list-inline">
                                            @if (Auth::check())
                                                <input type="submit" class="btn btn-primary" value="Add to watched serie" onclick="test()">
                                            @endif
                                        </ul><!--//meta-list-->
                                    </div><!--meta-->
                                </div><!--//content-->
                            </div><!--//post-inner-->
                        </article><!--//post-->
                    @endforeach
                </div>
            @endforeach

When a want to add a series to "watched series" the function test() is call :

function test(){
    alert($('.post-title').text());
}

When I am clicking on button, the alert box give me all original series name. I don't know how to display specific value.

Answers to

How to get specific value from many &lt;p&gt;

nr: #1 dodano: 2016-12-31 11:12

Pass the this context as the argument in the function call.

HTML:

<input type="submit" class="btn btn-primary" value="Add to watched serie" onclick="test(this)">

JS:

function test(ele){
    alert($(ele).closest('.post-inner').find('.post-title').text());
}
nr: #2 dodano: 2016-12-31 11:12

You can also try:

$(document).ready(function() {   
    $(document).on("click",".btn-primary",function() {
        alert($(this).closest('.post-inner').find('.post-title').text());
    });    
});
Source Show
◀ Wstecz