Skip to content

Commit

Permalink
add setTarget methods to AnchorElement
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Oct 16, 2024
1 parent d311152 commit 0aff8a8
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,43 @@ public AnchorElement removeHref() {
removeAttribute("href");
return this;
}

/**
* Sets the target for this href, if null or empty, remove the target attribute.
*
* @param target one of {@code _self}, {@code _blank}, {@code _parent}, {@code _top}, {@code
* _unfencedTop},
* @return The current {@link AnchorElement} instance.
*/
public AnchorElement setTarget(String target) {
if (isNull(target) || target.trim().isEmpty()) {
removeAttribute("target");
} else {
setAttribute("target", target);
}
return this;
}

/**
* Sets the target for this href, if null or empty, remove the target attribute.
*
* @param target {@link AnchorTarget}
* @return The current {@link AnchorElement} instance.
*/
public AnchorElement setTarget(AnchorTarget target) {
if (isNull(target)) {
removeAttribute("target");
} else {
setAttribute("target", target.name());
}
return this;
}

public enum AnchorTarget {
_self,
_blank,
_parent,
_top,
_unfencedTop;
}
}

0 comments on commit 0aff8a8

Please sign in to comment.