0

I want to call a javascript function from if statement of Laravel Blade. Is it possible?

@if(compareParent())
   Print Something
@endif

Javascript:

function compareParent() {
    $(".CategoryIDForModal").click(function () {
    var id = $(this).data(id);
    var parent_id = $('.subcategoryPID').text();

     console.log(id.id + " Parent: " + parent_id);
     if(id==parent_id)
    return true;
     else
    return false;
     })
}

1 Answer 1

1

No, the @if blade statement is evaluated server side and from a php processor, javascript is evaluated client side.

So you need to have a compareParent() function defined in php if you don't want to raise an error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.