brunodd brunodd - 4 months ago 12
HTML Question

haml - How to include 2 divs inside link?

I am trying to include 2 divs inside a link but the second div gets ignored. Any idea how to add 2 divs inside the link using haml?

= link_to '#' do
.div_one
Content div One
.div_two
Content div Two


I am getting this output:

<a href="#">
<div class="div_one">Content div One</div>
</a>
<div class="div_two">Content div Two</div>

Answer

You can do like so:

%a{:href => "#"}
  .div_one Content div One
  .div_two Content div Two

which gives the output

<a href="#">
  <div class="div_one">Content div One</div>
  <div class="div_two">Content div Two</div>
</a>

but I am without a proper compiler and have resorted to https://haml2erb.org/ so I cannot 100% verify as of right now.