Skip to content Skip to sidebar Skip to footer

Create New Div Arround Anchor Link When Clicked

How can I achieve this behaviors onclick with jquery : default state: Anchor click state

Solution 2:

Fastest way to do this:

$('a').click(function() {
  $(this).wrap($('<div/>', { 'class': 'highlight'}));
});

However, this is probably what you want, much simpler just use whatever CSS effect you want:

$('a').click(function() {
  $(this).addClass('highlight'});
});

Solution 3:

Checkout jQuery's wrap function.

$(this).wrap('<div class="highlight"></div>');

Solution 4:

Why don't you just style a:hover?

Something like this in CSS:

.highlighta {
    /* style */
}

.highlighta:hover {
    /* hover style */
}

Then change your HTML to:

<ahref="something.html"class='highlight'>Anchor</a>

Post a Comment for "Create New Div Arround Anchor Link When Clicked"