Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript & JQuery: how to bind the value to DOM element

Given below is part of my website

   <body controller="contr">
       <h1 bind="greeting"></h1>
        <p bind="text"></p>
   </body>

I need to bind the values of contr properties

   contr.greeting = 'Hello, World!';
   contr.text = 'Lorem Ipsum ..';

to h1 and p tags when:

     if controller == 'contr' 

so it will be interpreted as

     <h1 bind="greeting">Hello, World!</h1>
     <p bind="text">Lorem Ipsum ..</p>

How I can implement this in JQuery? What is best source to learn more about such DOM binding with JS and JQuery

like image 560
user3793667 Avatar asked Feb 11 '26 18:02

user3793667


1 Answers

<h1 bind="greeting">Jasper</h1>

<script language="javascript">
   $(document).ready(function () {
      $("h1[bind='greeting']").html('Hello World');
   });
</script>
like image 82
Jasper Giscombe Avatar answered Feb 15 '26 01:02

Jasper Giscombe