-2
<script>
   var idForDropDown = someValue;
</script>        
<ul class="dropdown-menu" id="'+ idForDropDown + '">
</ul>

When I check the id it takes idfordropwdown as a string and not assigns the value it has in javascript. Can someone tell what is the mistake I am doing? thanks.

1
  • Where's the "apex attribute"? All I see here is some generic HTML. You may want to just ask this question on Stack Overflow instead, or edit this question and make it more relevant to salesforce.com.
    – sfdcfox
    Jul 7, 2017 at 22:14

1 Answer 1

0

To modify markup values using JavaScript you have to execute JavaScript code in the client browser. (The HTML text has already been generated on the server.)

The code could be something like:

<ul class="dropdown-menu">
</ul>

<script>
var idForDropDown = someValue;
document.getElementsByClassName('dropdown-menu')[0].id = idForDropDown;
</script>

See documentation such as getElementsByClassName. Fairly unusual to be setting an id like that though.

If the id value can be worked out when the page is generated on the server (before it is passed to the client browser) and you were using Visualforce this would work because the id value is merged into the HTML text:

<ul class="dropdown-menu" id="{! idForDropDown  }">

Not the answer you're looking for? Browse other questions tagged .