Use the href of the link tag (<a>) to identify the operation

I create a tag as a button and use it instead of <button>or tags <input submit>.

To identify the operation, I use the href attribute, for example:

<a href='update'>Update</a>
<a href='delete'>Delete</a>

and then using jQuery: $ ('a [href = "update"]'). click (function () {...});

It works well. I also use the href attribute as the value for the operation parameter when this link acts like a submit button on the form.

Now the question is - will search engines punish me for blind links? (I think so). How do i work? use instead #update? I cannot use the attribute id, as there can be more than one button performing the same operation.

Note. The click handler can be connected using the class, which is quite convenient. Therefore, I would prefer not idto use several buttons to connect the same handler.

<!-- inside a form -->
<a href='update' class='submit-button'>Update</a>

<!-- inside $(function() { .. });
$('a.submit-button').click(function() {
    // 1. get href of the clicked link : href = $(this).attr('href');
    // 2. add <input hidden> to the form: <input type='hidden' name='operation' value='<href>'/>
    // 3. submit form : $(this).parents('form').submit();
});
+3
source share
4 answers

Why not just use a different attribute and keep it simple?

<a href="#" data-action="update">Update</a>
<a href="#" data-action="delete">Delete</a>

You can use whatever you want, but use is in data-accordance with HTML5 standards. But non-standard tags in any case will be ignored by all browsers, there are no drawbacks, except for the verification failure.

+2
source

"#update" "#insert", class . , ID, .

<a href="javascript:void(0);" class="update_buton submit_button">Update</a>

:

$('.update_button').click(function(e)
{
  // Do something here
});

, "submit_button" , :

$('.submit_button').click(function(e)
{
  // Common code up here

  if ( $(this).hasClass('.update_button') )
  {
    // Update here
  }
  else if ( $(this).hasClass('.other_button') )
  {
    // Other action here
  }

  // More common code down here
});
+5

href, .

id :

<a id="delete-017" class="delete-button">Item No. 17</a>

Btw, Stack Overflow... ( "link", "flag", "delete", "edit" )

+1

, href= "#" href= "# update" aka blind links.

SEO , , . / .

, ? , ? , , , , , , .

, jquery, , .

css jquery hooks, href , ... .

0

All Articles