JavaScript How run JavaScript with PHP variables javascript variables with dollar sign,javascript variables with underscore,javascript

Change your code to this:

<script type="text/javascript" language="javascript">
    $(document).ready(function(){
        $("#" + <?php echo $link[1] ?>).click(function(event){
        $("#content").load('<?php echo $link[0] ?>');
        return false;
        });
    });
</script>
Answer:1

You are not defining the array properly here.

$links = Array(
   $link = array('example.html', 'ex', 'Example')
);

I think a single array is enough for this case. Do -

$links = array('example.html', 'ex', 'Example');

Then this should work -

$("#content").load('<?php echo $links[0] ?>');

Update

php -

echo '<li><a target='_blank' href=subpage/'.$link[0].' id='.$link[1].' class="ex-links">'.$link[2].'</a><li>';

js -

<script type="text/javascript" language="javascript">
    $(document).ready(function(){
    $('ex-links').click(function(event){
    event.preventDefault();
    $("#content").load($(this).attr('href'));
    return false;
    });
    });
</script>
Answer:2

Try to use this instead

<script type="text/javascript" language="javascript">
    $(document).ready(function(){
        $(<?php echo '"#' . $link[1]'"'; ?>).click(function(event){
            $("#content").load(<?php echo "'" . $link[0]."'"; ?>);
            return false;
        });
    });
</script>

Kindly see if it proceeds.

Answer:3

Change your code to this:

<script type="text/javascript" language="javascript">
    $(document).ready(function(){
        $("#<?php echo $link[1]; ?>").click(function(event){
            $("#content").load('<?php echo $link[0] ?>');
            return false;
        });
    });
</script>

See that I fixed also the quotes in the first PHP echo.

Answer:4

The PHP code contains errors, and it also produces a mixing up of the attributes of the hyperlink (href and id), a mix up of the jQuery selector, and in addition I am puzzled why the a tag should contain both a link in the href attribute and a load event on the onclick event.

This begs for the question: did you not check the output and or are you not familiar with how the syntax should be?

The relative complexity of what you are doing here, versus the obvious numerous errors in the output suggest for an advice that you really first should study proper syntax and check the output in a debugger (browser developer tools).

The below works fine with me. I assume your not trying to load a full HTML page in a div element. The href attribute could as well be empty or target='_blank' href="#" as it serves no purpose.

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <title>Untitled Document</title>
    </head>

    <body>
        <?php
            $links = Array(
                $link = array('content.txt', 'ex', 'Example')
            );

            foreach ($links as $value => $link)
            {
                echo "<li><a target='_blank' href='{$link[0]}' id='{$link[1]}'>{$link[2]}</a></li>";
            }
        ?>

        <script type="text/javascript">
            $(document).ready(function(){
                $("#<?php echo $link[1] ?>").click(function(event){
                    $("#content").load('<?php echo $link[0] ?>');
                    return false;
                });
            });
        </script>
        <div id="content"></div>
    </body>
</html>
Answer:5

Is there a way to convert the following jQuery method to pure javascript? var myProps = $(".interp").map(function () { return this.id; }).get(); I do not know how many objects will be available ...

Is there a way to convert the following jQuery method to pure javascript? var myProps = $(".interp").map(function () { return this.id; }).get(); I do not know how many objects will be available ...

  1. jquery pure js
  2. jquery vs pure javascript
  3. jquery to pure javascript converter online
  4. jquery animate pure javascript
  5. jquery find pure javascript
  6. jquery to pure javascript converter
  7. jquery load pure javascript
  8. jquery append pure javascript
  9. jquery closest pure javascript
  10. jquery extend pure javascript
  11. jquery ajax pure javascript
  12. jquery vs pure javascript performance
  13. jquery ready pure javascript
  14. jquery offset pure javascript
  15. jquery html pure javascript
  16. jquery scrolltop pure javascript
  17. jquery each pure javascript
  18. jquery trigger pure javascript
  19. jquery selector pure javascript
  20. jquery css pure javascript

My overall goal was to take a screenshot via the background page using: http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab and pass it to the content script so I can use the ...

My overall goal was to take a screenshot via the background page using: http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab and pass it to the content script so I can use the ...

  1. chrome extension chrome ig story
  2. chrome extension chromecast
  3. chrome extension chrome store
  4. chrome extension chrome.tabs
  5. chrome extension chrome.tabs.query
  6. chrome extension chromevox
  7. chrome extension chrome.storage
  8. chrome extension chrome
  9. chrome extension chrome.runtime.sendmessage
  10. chrome extension chrometana
  11. chrome extension chrome.tabs undefined
  12. chrome extension chrome.downloads
  13. chrome extension chrome.runtime
  14. chrome extension chrome.windows.create
  15. chrome extension chrome.tabs.onupdated.addlistener
  16. chrome extension chrome.tabs.create
  17. chrome extension chromecast video stream
  18. chrome extension chrome remote desktop
  19. chrome extension chrome.storage.local
  20. chrome extension chrome.debugger

I'm working on a terminal-like modal, using bootstrap's and I want to clear it when the user presses Ctrl+L like it does when he writes clear in it. But the problem is, when I press Ctrl+L, it focuses ...

I'm working on a terminal-like modal, using bootstrap's and I want to clear it when the user presses Ctrl+L like it does when he writes clear in it. But the problem is, when I press Ctrl+L, it focuses ...

  1. prevent focus with css
  2. prevent focus on click
  3. prevent focus on element
  4. prevent focus on input
  5. prevent focus on button
  6. prevent focus on readonly input
  7. prevent focus on tab
  8. prevent focus on element css
  9. prevent focus on div
  10. prevent focus on click css
  11. prevent focus on button click
  12. prevent focus on click input
  13. prevent focus on iframe
  14. prevent focus on click react
  15. prevent focus on click jquery
  16. prevent focus on mousedown
  17. prevent focus on hidden element
  18. prevent focus on input element
  19. prevent focus in html
  20. prevent on focus

I am trying to place an element, "inner", flush against the upper right hand corner of another div, "outer", using absolute positioning. The "inner" element is not a child of "outer". I therefore need ...

I am trying to place an element, "inner", flush against the upper right hand corner of another div, "outer", using absolute positioning. The "inner" element is not a child of "outer". I therefore need ...

  1. place element inside div
  2. jquery place element inside div
  3. javascript place element inside another
  4. jquery place element inside another