0

i have a text inside an element. This text will changed according to a jQuery. As it changes, I need to pull that text as a php variable. This variable will be used later in the same document.

<div id="divId">sometext<div>

now, I want to assign a php code to assign "sometext" as the variable

I need the below;

    <div id="divId">
    sometext
    <?php
    $variable = (get text from "divId");
    ?>
    <div>

then I can use it somewhere else like

<div>
<?php
if($variable == "sometext")
{
echo ($variable);
}
?>
<div>

I need help on the (get text from "divId")part

1
  • 2
    Once the PHP is sent to the client, PHP no longer has any control. You'll have to use Javascript to do anything. Commented Oct 17, 2016 at 5:30

1 Answer 1

1

You cant do with PHP. please use javascript or jquery

please find way of jquery

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var getDivValue = $('#divId').html();
    if(getDivValue == 'sometext'){
        $('#divId').html('updateText');
    }else if(getDivValue == 'other'){
         $('#divId').html('updateTextTwo');
    }
});
</script>
</head>
<body>
<div id="divId">sometext</div>

</body>
</html>

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.